@@ -73,7 +73,7 @@ class RawMetadata(CorvaBaseEvent):
73
73
RecordsDepth = Sequence [RawDepthRecord ]
74
74
else :
75
75
RecordsBase = pydantic .conlist (RawBaseRecord , min_items = 1 )
76
- RecordsTime = pydantic .conlist (RawTimeRecord , min_items = 1 )
76
+ RecordsTime = pydantic .conlist (RawTimeRecord , min_items = 0 )
77
77
RecordsDepth = pydantic .conlist (RawDepthRecord , min_items = 1 )
78
78
79
79
@@ -105,7 +105,10 @@ def is_completed(self) -> bool:
105
105
There can only be 1 completed record always located at the end of the list.
106
106
"""
107
107
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"
109
112
110
113
@property
111
114
def max_record_value (self ) -> Union [int , float ]:
@@ -165,33 +168,48 @@ def filter_records(
165
168
def set_asset_id (cls , values : dict ) -> dict :
166
169
"""Calculates asset_id field."""
167
170
168
- records : List [RawBaseRecord ] = values [' records' ]
171
+ records : List [RawBaseRecord ] = values [" records" ]
169
172
170
- values ["asset_id" ] = int (records [0 ].asset_id )
173
+ if records :
174
+ values ["asset_id" ] = int (records [0 ].asset_id )
171
175
172
176
return values
173
177
174
178
@pydantic .root_validator (pre = False , skip_on_failure = True )
175
179
def set_company_id (cls , values : dict ) -> dict :
176
180
"""Calculates company_id field."""
177
181
178
- records : List [RawBaseRecord ] = values [' records' ]
182
+ records : List [RawBaseRecord ] = values [" records" ]
179
183
180
- values ["company_id" ] = int (records [0 ].company_id )
184
+ if records :
185
+ values ["company_id" ] = int (records [0 ].company_id )
181
186
182
187
return values
183
188
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
+
184
202
185
203
class RawStreamTimeEvent (RawStreamEvent ):
186
204
records : RecordsTime
187
205
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"
189
207
190
208
191
209
class RawStreamDepthEvent (RawStreamEvent ):
192
210
records : RecordsDepth
193
211
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"
195
213
log_identifier : str = None # type: ignore
196
214
197
215
@pydantic .root_validator (pre = False , skip_on_failure = True )
0 commit comments