@@ -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 ]
0 commit comments