-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading behavior of optional fields is inconsistent when using nested pydantic models #895
Comments
@sultaniman looking #901 we can't really fix how we map Pydantic models into our schema fully. It may require some conceptual change. It is a good outcome of the research. Still we should fix this ticket and we can be (a little) hacky. We'll ignore recurring into lists for now (those generate dlt tables) but we can support nested pydantic models (that are not part of the list). We we see a Pydantic model like in @codingcyclist example below we should recursively create a dlt schema from it and then flatten this model into parent model. we use later we'll fix it end to end. my current take that we should let people define models for tables and create relational schemas only in normalize. but that's for later |
Amazing, I will take a look at the PR later tonight |
@codingcyclist with implementation and all related reviews this has been merged now. |
dlt version
0.4.2
Describe the problem
Context:
Parent
as a nested pydantic model to enforce a schema on a rescue.skip_complex_types
on the parent model toTrue
andmax_table_nesting
on the resource to1
so that my child model does not get coerced into a singlecomplex
column or into several child tables, but flattened into several columns (i.e.child__{child-column-name}
)Current behavior:
The optional child model field won’t appear as a
child__optional_child_attribute
column in the destination until the first data comes through where this filed is not None. The optional parent attribute, however, appears as andoptional_parent_attribute
column from the first time when the resource gets loaded.The problem here seems to be that the table schema has no knowledge about the data type of child model attributes as the schema is being generated before the flattening logic gets applied.
Expected behavior
Optional child model fields should always get loaded into the destination if they have a primitive data type
Steps to reproduce
See above
Operating system
macOS
Runtime environment
Local
Python version
3.11
dlt data source
Custom (i.e. AWS EventBridge)
dlt destination
Snowflake
Other deployment details
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: