fix(ingest/mongodb): fix schema inference for lists of values (#9145)

This commit is contained in:
Harshal Sheth 2023-11-01 16:58:37 -07:00 committed by GitHub
parent 932eebea35
commit 50789224a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@ class SchemaDescription(BasicSchemaDescription):
nullable: bool # if field is ever missing
def is_field_nullable(doc: Dict[str, Any], field_path: Tuple) -> bool:
def is_field_nullable(doc: Dict[str, Any], field_path: Tuple[str, ...]) -> bool:
"""
Check if a nested field is nullable in a document from a collection.
@ -54,7 +54,10 @@ def is_field_nullable(doc: Dict[str, Any], field_path: Tuple) -> bool:
# count empty lists of nested objects as nullable
if len(value) == 0:
return True
return any(is_field_nullable(x, remaining_fields) for x in doc[field])
return any(
isinstance(x, dict) and is_field_nullable(x, remaining_fields)
for x in doc[field]
)
# any other types to check?
# raise ValueError("Nested type not 'list' or 'dict' encountered")