Skip to content

Commit cb1e50e

Browse files
authored
Merge pull request #183 from FEWS-NET/HEA-572/fix_fixtures
Fix minor errors in fixtures - see HEA-572
2 parents 3d606bf + 7bb1fee commit cb1e50e

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

pipelines/assets/fixtures.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def validate_instances(
110110
+ instance["livelihood_strategy"][2:] # strategy_type, season, product_id, additional_identifier
111111
+ [instance["wealth_group"][3]] # full_name
112112
)
113+
elif model_name == "WealthGroupCharacteristicValue":
114+
instance["natural_key"] = instance["wealth_group"][
115+
:3 # livelihood_zone, reference_year_end_date, wealth_group_category
116+
] + [
117+
instance["wealth_characteristic_id"],
118+
instance["reference_type"],
119+
instance["product_id"] or "", # Natural key components must be "" rather than None
120+
instance["wealth_group"][3], # full_name
121+
]
113122
# The natural key is a list of strings, or possibly numbers, so validate that here to avoid confusing
114123
# error messages later.
115124
if "natural_key" not in instance:
@@ -145,7 +154,7 @@ def validate_instances(
145154
if column not in instance:
146155
error = f"Missing mandatory field {field.name} for {record_reference}"
147156
model_errors.append(error)
148-
elif not instance[column]:
157+
elif not instance[column] and not instance[column] == 0:
149158
error = f"Missing value for mandatory field {column} for {record_reference}"
150159
model_errors.append(error)
151160
# Ensure the instances contain valid parent references for foreign keys
@@ -419,13 +428,8 @@ def imported_communities(
419428
"""
420429
Communities from a BSS, imported to the Django database using a fixture.
421430
"""
422-
fixture, metadata = get_fixture_from_instances(community_instances)
423-
metadata = import_fixture(fixture)
424-
425-
return Output(
426-
None,
427-
metadata=metadata,
428-
)
431+
output = get_fixture_from_instances(community_instances)
432+
return import_fixture(output.value)
429433

430434

431435
@asset(partitions_def=bss_instances_partitions_def)

pipelines/assets/wealth_characteristic.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,7 @@ def wealth_characteristic_valid_instances(
531531
Valid WealthGroup and WealthGroupCharacteristicValue instances from a BSS, ready to be loaded via a Django fixture.
532532
"""
533533
partition_key = context.asset_partition_key_for_output()
534-
valid_instances, metadata = validate_instances(context, config, wealth_characteristic_instances, partition_key)
535-
metadata = {f"num_{key.lower()}": len(value) for key, value in valid_instances.items()}
536-
metadata["total_instances"] = sum(len(value) for value in valid_instances.values())
537-
metadata["preview"] = MetadataValue.md(
538-
f"```json\n{json.dumps(valid_instances, indent=4, ensure_ascii=False)}\n```"
539-
)
540-
return Output(
541-
valid_instances,
542-
metadata=metadata,
543-
)
534+
return validate_instances(context, config, wealth_characteristic_instances, partition_key)
544535

545536

546537
@asset(partitions_def=bss_instances_partitions_def, io_manager_key="json_io_manager")

0 commit comments

Comments
 (0)