-
Notifications
You must be signed in to change notification settings - Fork 212
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
fix: required fields in nested pydantic models need to follow parent nullability #2199
base: devel
Are you sure you want to change the base?
fix: required fields in nested pydantic models need to follow parent nullability #2199
Conversation
✅ Deploy Preview for dlt-hub-docs canceled.
|
@rudolfix I think it makes sense to forward the nullability to flattened fields, wdyt? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just small changes, then we can merge this.
|
||
|
||
def test_parent_nullable_means_children_nullable(): | ||
class MyParent(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joscha could you add the reverse test? Another field with a non optional child model and test that this is not nullable? Then make sure the conflicts are solved and the linter passes, then we can merge this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, good point, will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inverse test in 74af54c
0212eb0
to
74af54c
Compare
Changes are in @sh-rp. Unsure about the failing |
@joscha looks good to me, thanks! Could you merge in devel (or rebase) to make sure the tests pass? |
This comment was marked as outdated.
This comment was marked as outdated.
…sted-must-be-nullable
Description
Fields of nested pydantic models that are not kept as JSON via
skip_nested_types=True
need to follow the "requiredness" of their parent.Example:
results in a table that looks like this:
table
B
:which is incorrect as I can serialize an instance of
B
that does not have achild_a
, and thus, by extension, noid
forchild_a
.The change in this pull request retains the nullability of the field that contains the nested model, effectively making any required field of a nested, flattened model nullable as well if the parent model field is optional, i.e. the resulting table with the change in this PR is:
table
B
:If we agree this is a bug and the fix in this PR is the way to go I can add a test & fix for deeply nested models as well.