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 usage of AliasGenerator with computed_field decorator #8806

Merged
merged 8 commits into from Feb 13, 2024

Conversation

sydney-runkle
Copy link
Member

@sydney-runkle sydney-runkle commented Feb 13, 2024

Fix #8768

Ensure that AliasGenerator is handled properly when using it along with a computed_field in a model.

Selected Reviewer: @samuelcolvin

@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Feb 13, 2024
Copy link

cloudflare-pages bot commented Feb 13, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ef959d9
Status: ✅  Deploy successful!
Preview URL: https://82e9754c.pydantic-docs2.pages.dev
Branch Preview URL: https://alias-gen-fixes.pydantic-docs2.pages.dev

View logs

@sydney-runkle
Copy link
Member Author

Please review

Copy link

codspeed-hq bot commented Feb 13, 2024

CodSpeed Performance Report

Merging #8806 will not alter performance

Comparing alias-gen-fixes (ef959d9) with main (071c2c8)

Summary

✅ 10 untouched benchmarks

# note that we use the serialization_alias with priority over alias, as computed_field
# aliases are used for serialization only (not validation)
if computed_field_info.alias_priority == 1:
computed_field_info.alias = serialization_alias or alias
Copy link
Contributor

Choose a reason for hiding this comment

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

I would do

Suggested change
computed_field_info.alias = serialization_alias or alias
computed_field_info.alias = serialization_alias if serialization_alias is not None else alias

to handle the case of serialization_alias = '' and alias != ''. Probably worth a comment about why, though not a test.

I could be convinced not to do that but I do think there are tests for the alias = '' case elsewhere in the codebase.

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 think we should do this, but in a different PR, to both the field_info logic and the computed_field_info logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, doesn't seem like an urgent change 👍

@sydney-runkle sydney-runkle merged commit b290b31 into main Feb 13, 2024
54 checks passed
@sydney-runkle sydney-runkle deleted the alias-gen-fixes branch February 13, 2024 21:43
sydney-runkle added a commit that referenced this pull request Mar 8, 2024
Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AliasGenerator causes computed_field to throw an error when generating schema
3 participants