-
Notifications
You must be signed in to change notification settings - Fork 221
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
Deserialize NestedField initial-default and write-default Attributes #1432
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,35 @@ def table_schema_simple() -> Schema: | |
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: wydt about adding an NestedField to table_schema_simple instead of creating a new Schema altogether? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can make that change and see what happens. I was hesitant because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 if it becomes too tedious, the current test is fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were ~25 test failures when changing I can probably figure it out, but might take a bit longer until I find time. |
||
def table_schema_with_full_nested_fields() -> Schema: | ||
return schema.Schema( | ||
NestedField( | ||
field_id=1, | ||
name="foo", | ||
field_type=StringType(), | ||
required=False, | ||
doc="foo doc", | ||
initial_default="foo initial", | ||
write_default="foo write", | ||
), | ||
NestedField( | ||
field_id=2, name="bar", field_type=IntegerType(), required=True, doc="bar doc", initial_default=42, write_default=43 | ||
), | ||
NestedField( | ||
field_id=3, | ||
name="baz", | ||
field_type=BooleanType(), | ||
required=False, | ||
doc="baz doc", | ||
initial_default=True, | ||
write_default=False, | ||
), | ||
schema_id=1, | ||
identifier_field_ids=[2], | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def table_schema_nested() -> Schema: | ||
return schema.Schema( | ||
|
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.
curious if we should do the same here too
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.
I originally had that, but the tests seem to pass without it so I just kept it as is. Happy to change if you'd like.
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.
weird, im trying to figure out when this bug occurs and see if its present in other places in the codebase
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.
Let me know what you find, I tried digging into Pydantic to understand why it happens, but ran out of time.
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.
I went down a rabbit hole, here's what I learned.
__init__
with a pydantic model is kind of an anti-pattern; the pydantic model typically handles all the initialization/validation.__init__
here is to provide the ability to initializeNestedField
with positional args, i.e.NestedField(1, "blah")
For backward compatibility, we can't change
NestedField
to not take positional args.But we can make this
__init__
(and other__init__
s) more resilient to bugs with something likeThis doesn't check for when using both positional and keyword args, i.e.
NestedField(1, field_id=10)
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.
That could work, my only worry would be that ordinarily minor changes like changing field order in the class definition would break consumers in unexpected ways.
For example, this instantiation works fine:
If someone (for some reason) changed field order or adds a new field in the middle, for example:
Then the instantiation breaks:
Tests could catch that, but it might get a bit painful to deal with.
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.
Yes, this is a bit messy, but it enables positional arguments. Otherwise, you would always need to specify the keyword-arguments which is pretty verbose :) If we decide to change this, that's fine, but probably in a separate PR :)