Skip to content
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

[BUGFIX] zep - always serialize type field #7056

Merged
merged 14 commits into from
Feb 7, 2023

Conversation

Kilo59
Copy link
Member

@Kilo59 Kilo59 commented Feb 6, 2023

#7009 changed the default behavior of all ZEP class serialization methods to exclude any fields that haven't been explicitly set.
Without this change, we would end up with configs full of default field values.
However, we always need the value of type in order to determine the correct asset class/type to use.

Changes proposed in this pull request:

  • always serialize the Datasource and DataAsset type field

@netlify
Copy link

netlify bot commented Feb 6, 2023

Deploy Preview for niobium-lead-7998 ready!

Name Link
🔨 Latest commit 75a832a
🔍 Latest deploy log https://app.netlify.com/sites/niobium-lead-7998/deploys/63e1b997e7283e00099f9e45
😎 Deploy Preview https://deploy-preview-7056--niobium-lead-7998.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@ghost
Copy link

ghost commented Feb 6, 2023

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Comment on lines +652 to +653
# type should be in dumped str even if not explicitly set
assert f"type: {asset.type}" in source_str
Copy link
Member Author

@Kilo59 Kilo59 Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note. These 3 test_postgres_datasource.py tests are the only ones that I could actually get to catch the error.
This only happens when an asset is created in code and no type field is set.

I couldn't reproduce it with any of the config tests (as expected).

),
],
)
def test_type_field_always_dumped(ds_w_assets: dict):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test didn't actually catch the error so it's of questionable value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because you are using a dictionary with the type field defined and checking that the type field roundtrips?
If you don't think this adds value then feel free to remove it.

Copy link
Member Author

@Kilo59 Kilo59 Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the only way to reproduce the type field not being serialized error is when adding assets "in-code". Because that's the only place where the default type field value is used. And because the default is used, pydantic doesn't consider the field as having been "set".

So when we dump the model with exclude_unset=True it gets left out.
https://docs.pydantic.dev/usage/exporting_models/#modeldict
Note in the above docs it says exclude_unset defaults to False, but we've changed this behavior to default to True

When we read from config (dict, yaml or json) everything (including type) gets loaded into the DataAsset class constructer and so pydantic considers it set, that's why the test_config.py tests didn't catch the issue.

So.... I'll delete these new test_config.py tests and leave the changes to test_postgres_datasource.py

@Kilo59 Kilo59 marked this pull request as ready for review February 6, 2023 02:09
@Kilo59 Kilo59 self-assigned this Feb 6, 2023
@Kilo59 Kilo59 added the zep Zero Entry Pool work label Feb 6, 2023
@Kilo59 Kilo59 requested a review from billdirks February 6, 2023 03:22
Copy link
Contributor

@billdirks billdirks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM. One question responding to your comment.

),
],
)
def test_type_field_always_dumped(ds_w_assets: dict):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because you are using a dictionary with the type field defined and checking that the type field roundtrips?
If you don't think this adds value then feel free to remove it.

@Kilo59 Kilo59 enabled auto-merge (squash) February 7, 2023 00:03
@Kilo59 Kilo59 merged commit cd47995 into develop Feb 7, 2023
@Kilo59 Kilo59 deleted the b/great-1663/zep-serialize-type-field branch February 7, 2023 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-team platform zep Zero Entry Pool work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants