@@ -40,56 +40,42 @@ def metadata_checks(self):
4040 ingested_metadata = self .ingested_record .metadata
4141 stored_metadata = self .stored_record .metadata
4242
43+ # Match timestamp with or without timezone info
4344 try :
44- time_match = ( ingested_metadata .timestamp ) .replace (
45+ time_match = ingested_metadata .timestamp .replace (
4546 tzinfo = None ,
4647 ) == stored_metadata .timestamp .replace (tzinfo = None )
4748 except Exception :
48- time_match = ( ingested_metadata .timestamp ) == stored_metadata .timestamp
49+ time_match = ingested_metadata .timestamp == stored_metadata .timestamp
4950
50- epac_match = (
51- ingested_metadata .epac_ops_data_version
52- == stored_metadata .epac_ops_data_version
53- )
54- shot_match = ingested_metadata .shotnum == stored_metadata .shotnum
5551 area_match = ingested_metadata .active_area == stored_metadata .active_area
5652 experiment_match = (
5753 ingested_metadata .active_experiment == stored_metadata .active_experiment
5854 )
5955
60- if time_match and epac_match and shot_match and area_match and experiment_match :
56+ shot_match = ingested_metadata .shotnum == stored_metadata .shotnum
57+
58+ # Reject if shotnum matches but timestamp doesn't
59+ if shot_match and not time_match :
60+ raise RejectRecordError ("a record with this shotnum already exists" )
61+
62+ # Accept merge if everything matches
63+ if shot_match and time_match and area_match and experiment_match :
6164 log .info ("record metadata matches existing record perfectly" )
6265 return "accept_merge"
6366
64- elif (
65- time_match
66- and not epac_match
67- and not shot_match
68- and not area_match
69- and not experiment_match
70- ):
71- raise RejectRecordError ("timestamp matches, other metadata does not" )
72-
73- elif (
74- shot_match
75- and not time_match
76- and not epac_match
77- and not area_match
78- and not experiment_match
79- ):
80- raise RejectRecordError ("shotnum matches, other metadata does not" )
81-
82- elif not time_match and not shot_match :
67+ # Accept as new record if both timestamp and shotnum are unique
68+ if not time_match and not shot_match :
8369 return "accept_new"
8470
85- else :
86- log .error (
87- "Metadata for file being ingested: %s, metadata for file stored in "
88- " database: %s" ,
89- ingested_metadata ,
90- stored_metadata ,
91- )
92- raise RejectRecordError ("inconsistent metadata" )
71+ # All other cases are inconsistent
72+ log .error (
73+ "Metadata for file being ingested: %s, metadata for file "
74+ "stored in database: %s" ,
75+ ingested_metadata ,
76+ stored_metadata ,
77+ )
78+ raise RejectRecordError ("inconsistent metadata" )
9379
9480 def channel_checks (
9581 self ,
0 commit comments