Skip to content

Commit

Permalink
pk is not a required key
Browse files Browse the repository at this point in the history
  • Loading branch information
smnorris committed Aug 16, 2024
1 parent 0b9f01e commit 932c3ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 5 additions & 4 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def validate_file(source):

# are expected columns present?
columns = [x.lower() for x in df.columns]
if source["primary_key"]:
if source["primary_key"] not in columns:
# is primary key present and not null?
if "primary_key" in source and source["primary_key"]:
if source["primary_key"].lower() not in columns:
raise ValueError(
f"Validation error: {source['alias']} - primary key is not present - {source['primary_key']}"
)
Expand Down Expand Up @@ -110,8 +111,8 @@ def validate_bcgw(source):
table_def = bcdata.get_table_definition(table)
columns = [c["column_name"] for c in table_def["schema"]]

# is primary key present?
if source["primary_key"]:
# is primary key present and not null?
if "primary_key" in source and source["primary_key"]:
if source["primary_key"] not in columns:
raise ValueError(
f"Validation error: {source['alias']} - Primary key - {source['primary_key']} is not present in {table}"
Expand Down
8 changes: 2 additions & 6 deletions sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,7 @@
"source_type": "FILE",
"layer": "GBRSchD_GB_20151105",
"query": "GB_CLASS = 2",
"field_mapper": {
"name": "GB_CLASS"
},
"field_mapper": {"name": "GB_CLASS"},
"data": {"harvest_restriction": 5}
},
{
Expand All @@ -441,9 +439,7 @@
"source_type": "FILE",
"layer": "BC_Boundary_Terrestrial_Singlepart",
"query": null,
"field_mapper": {
"name": null
},
"field_mapper": {"name": null},
"data": {"harvest_restriction": 6}
}
]

0 comments on commit 932c3ad

Please sign in to comment.