Skip to content

Commit 4aee838

Browse files
committed
Minor fixes for livelihood activities - see HEA-573
1 parent 761cbdf commit 4aee838

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

pipelines/assets/fixtures.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ def validate_instances(
5454

5555
instances = {**instances, **subclass_livelihood_activities}
5656

57-
valid_instances = {}
58-
valid_keys = {}
57+
valid_instances = {model_name: [] for model_name in instances}
58+
valid_keys = {model_name: [] for model_name in instances}
5959
errors = []
60+
current_timestamp = datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
6061
for model_name, model_instances in instances.items():
6162

6263
# Ignore models where we don't have any instances to validate.
@@ -72,9 +73,6 @@ def validate_instances(
7273
for field in model._meta.concrete_fields
7374
if field.get_attname() not in valid_field_names
7475
]
75-
valid_instances[model_name] = []
76-
valid_keys[model_name] = []
77-
current_timestamp = datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
7876

7977
# Iterate over the instances, validating each one in turn
8078
for i, instance in enumerate(model_instances):
@@ -99,7 +97,10 @@ def validate_instances(
9997
elif model_name == "LivelihoodStrategy":
10098
instance["natural_key"] = instance["livelihood_zone_baseline"] + [
10199
instance["strategy_type"],
102-
instance["season"] or "", # Natural key components must be "" rather than None
100+
# instance['season'] is a natural key itself, so it is stored as a list even though it only
101+
# has a single component - the season name - so take the first element of the list.
102+
# Natural key components must be "" rather than None
103+
instance["season"][0] if instance["season"] else "",
103104
instance["product_id"] or "", # Natural key components must be "" rather than None
104105
instance["additional_identifier"],
105106
]

pipelines/assets/other_cash_income.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def other_cash_income_instances(
134134
LivelhoodStrategy and LivelihoodActivity instances extracted from the BSS.
135135
"""
136136
if other_cash_income_dataframe.empty:
137-
return {}
137+
return Output({}, metadata={"message": "No Data2 worksheet found in this BSS"})
138138

139139
return get_annotated_instances_from_dataframe(
140140
context,

pipelines/assets/wild_foods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def wild_foods_instances(
144144
LivelhoodStrategy and LivelihoodActivity instances extracted from the BSS.
145145
"""
146146
if wild_foods_dataframe.empty:
147-
return {}
147+
return Output({}, metadata={"message": "No Data3 worksheet found in this BSS"})
148148

149149
return get_annotated_instances_from_dataframe(
150150
context,

0 commit comments

Comments
 (0)