Skip to content

Commit dc0d70e

Browse files
committed
AB#101818 Skip id fields if this is only an internal field
Some id fields are only there to give Django a non-composite PK.
1 parent 9ea3cfe commit dc0d70e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/schematools/exports/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,7 @@ def _get_fields(dataset_schema: DatasetSchema, table: DatasetTableSchema, scopes
128128
for field in table.fields:
129129
if field.is_array:
130130
continue
131+
if field.is_internal:
132+
continue
131133
if parent_scopes | set(field.auth) - {_PUBLIC_SCOPE} <= set(scopes):
132134
yield field

src/schematools/types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,11 @@ def is_identifier_part(self) -> bool:
14341434
self.id == "id" or self._id in self._parent_table.identifier
14351435
) and self._parent_field is None
14361436

1437+
@cached_property
1438+
def is_internal(self) -> bool:
1439+
"""Id fields for table with composite key is only for internal (Django) use."""
1440+
return self.is_primary and self._parent_table.has_composite_key
1441+
14371442
@cached_property
14381443
def relation(self) -> str | None:
14391444
"""Give the 1:N relation, if it exists."""

tests/test_export.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_csv_export_only_actual(here, engine, ggwgebieden_schema, dbsession, tmp
3737
with open(tmp_path / "ggwgebieden_ggwgebieden.csv") as out_file:
3838
lines = out_file.readlines()
3939
assert len(lines) == 2 # includes the headerline
40-
assert lines[1].split(",")[1] == "2" # volgnummer == 2
40+
assert lines[1].split(",")[0] == "2" # volgnummer == 2
4141

4242

4343
def test_jsonlines_export(here, engine, meetbouten_schema, dbsession, tmp_path):

0 commit comments

Comments
 (0)