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

🐛 Fix aliases priority #6023

Merged
merged 2 commits into from Jun 7, 2023
Merged

🐛 Fix aliases priority #6023

merged 2 commits into from Jun 7, 2023

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Jun 6, 2023

Change Summary

Fix aliases priority.

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jun 6, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f148284
Status: ✅  Deploy successful!
Preview URL: https://b10b3bdc.pydantic-docs2.pages.dev
Branch Preview URL: https://fix-alias-priority.pydantic-docs2.pages.dev

View logs

@@ -238,6 +238,62 @@ class Child(Parent):
assert [f.serialization_alias for f in Child.model_fields.values()] == ['w_ser_alias', 'X', 'Y', 'Z']


def test_aliases_priority():
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we break these into separate tests? I don't like redefining the type multiple times in the same test, I got super confused for a minute because I looked halfway down after seeing the definition at the top before I realized the type was getting redefined in each block

Copy link
Contributor

Choose a reason for hiding this comment

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

(Also would be annoying to debug if something breaks some of these cases and not others, as it will fail out on the first one rather than letting you see precisely which ones fail.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Could also use pytest.mark.parametrize but no need if it's hard to structure the code in a parametric way — I think it's fine to just have a handful of similar-but-different tests if that's easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to parametrize, but this case it didn't look that bad... 👀

Copy link
Contributor

@dmontagu dmontagu left a comment

Choose a reason for hiding this comment

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

Other than wanting the mega test split up, this looks good to me

class Model(BaseModel, alias_generator=str.upper):
x: int = Field(..., serialization_alias='x1')

# validation_alias should take priority over alias_generator
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# validation_alias should take priority over alias_generator
# serialization_alias should take priority over alias_generator

I believe this is a copy-paste error

@Kludex Kludex enabled auto-merge (squash) June 7, 2023 09:08
@Kludex Kludex merged commit eb7165e into main Jun 7, 2023
51 checks passed
@Kludex Kludex deleted the fix/alias-priority branch June 7, 2023 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants