File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,13 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
224
224
225
225
def create_model_instance (model : Type [BaseModel ], data : dict ):
226
226
nested_fields = get_nested_fields (model )
227
+
228
+ # Handle flat models (like Pressure) that have a single main field
229
+ if len (model .__fields__ ) == 2 and "timestamp" in model .__fields__ :
230
+ main_field = next (field for field in model .__fields__ if field != "timestamp" )
231
+ if main_field not in data and model .__name__ in new_collections :
232
+ data [main_field ] = data .get (new_collections [model .__name__ ])
233
+
227
234
for field_name , nested_model in nested_fields .items ():
228
235
if field_name in data :
229
236
if isinstance (data [field_name ], list ):
@@ -334,6 +341,13 @@ def get_uniform_sample_pipeline(
334
341
project_pipeline = create_nested_pipeline (response_model )
335
342
project_pipeline ["timestamp" ] = "$timestamp"
336
343
344
+ # Handle flat models (like Pressure) that have a single main field
345
+ if len (response_model .__fields__ ) == 2 and "timestamp" in response_model .__fields__ :
346
+ main_field = next (field for field in response_model .__fields__ if field != "timestamp" )
347
+ project_pipeline [main_field ] = (
348
+ f"${ new_collections .get (response_model .__name__ , main_field )} "
349
+ )
350
+
337
351
pipeline = [
338
352
{"$match" : match_clause },
339
353
{
You can’t perform that action at this time.
0 commit comments