@@ -73,7 +73,7 @@ class RawMetadata(CorvaBaseEvent):
7373 RecordsDepth = Sequence [RawDepthRecord ]
7474else :
7575 RecordsBase = pydantic .conlist (RawBaseRecord , min_items = 1 )
76- RecordsTime = pydantic .conlist (RawTimeRecord , min_items = 1 )
76+ RecordsTime = pydantic .conlist (RawTimeRecord , min_items = 0 )
7777 RecordsDepth = pydantic .conlist (RawDepthRecord , min_items = 1 )
7878
7979
@@ -105,7 +105,10 @@ def is_completed(self) -> bool:
105105 There can only be 1 completed record always located at the end of the list.
106106 """
107107
108- return self .records [- 1 ].collection == 'wits.completed'
108+ if not self .records :
109+ return False
110+
111+ return self .records [- 1 ].collection == "wits.completed"
109112
110113 @property
111114 def max_record_value (self ) -> Union [int , float ]:
@@ -165,33 +168,48 @@ def filter_records(
165168 def set_asset_id (cls , values : dict ) -> dict :
166169 """Calculates asset_id field."""
167170
168- records : List [RawBaseRecord ] = values [' records' ]
171+ records : List [RawBaseRecord ] = values [" records" ]
169172
170- values ["asset_id" ] = int (records [0 ].asset_id )
173+ if records :
174+ values ["asset_id" ] = int (records [0 ].asset_id )
171175
172176 return values
173177
174178 @pydantic .root_validator (pre = False , skip_on_failure = True )
175179 def set_company_id (cls , values : dict ) -> dict :
176180 """Calculates company_id field."""
177181
178- records : List [RawBaseRecord ] = values [' records' ]
182+ records : List [RawBaseRecord ] = values [" records" ]
179183
180- values ["company_id" ] = int (records [0 ].company_id )
184+ if records :
185+ values ["company_id" ] = int (records [0 ].company_id )
181186
182187 return values
183188
189+ @pydantic .validator ("records" , pre = True )
190+ def validate_records (cls , v ):
191+ if isinstance (v , List ):
192+ return [
193+ record
194+ for record in v
195+ if (
196+ (isinstance (record , dict ) and record .get ("data" ) is not None )
197+ or (hasattr (record , "data" ) and record .data is not None )
198+ )
199+ ]
200+ return v
201+
184202
185203class RawStreamTimeEvent (RawStreamEvent ):
186204 records : RecordsTime
187205 rerun : Optional [RerunTime ] = None
188- _max_record_value_cache_key : ClassVar [str ] = ' last_processed_timestamp'
206+ _max_record_value_cache_key : ClassVar [str ] = " last_processed_timestamp"
189207
190208
191209class RawStreamDepthEvent (RawStreamEvent ):
192210 records : RecordsDepth
193211 rerun : Optional [RerunDepth ] = None
194- _max_record_value_cache_key : ClassVar [str ] = ' last_processed_depth'
212+ _max_record_value_cache_key : ClassVar [str ] = " last_processed_depth"
195213 log_identifier : str = None # type: ignore
196214
197215 @pydantic .root_validator (pre = False , skip_on_failure = True )
0 commit comments