Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Do not cache parametrized models when in the process of parametrizing another model#10704

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sydney-runkle merged 4 commits intomainfrom10279-2
Jan 7, 2025

Conversation

Viicos
Copy link
Member

@ViicosViicos commentedOct 24, 2024
edited
Loading

Change Summary

Fixes#10279, partiallyfixes#9887.

We avoid caching parametrized models when in the process of parametrizing another model, as the result ofBaseModel.__class_getitem__ can returnPydanticRecursiveRef instances in this case. In the model core schema generation logic, we mutateFieldInfo instances if the annotation wasn't evaluated yet, meaning we could set the annotation to some typing construct containing aPydanticRecursiveRef, e.g. with:

classModel1[T](BaseModel):# When evaluated, this annotation will be a `PydanticRecursiveRef`model2:'Model2[T]'classModel2[S](BaseModel):model1:Model1[S]

Because theseFieldInfo instances come from themodel_fields attribute of the model class, having the caching logic here can result in a parametrized model class with aFieldInfo containingPydanticRecursiveRef instances when we later parametrize a model (e.g.Model1[str]).

Note that is hopefully not a long term solution, as this doesn't fix what is an even simpler repro:#9969.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review,please add a comment including the phrase "please review" to assign reviewers

@cloudflare-workers-and-pagesCloudflare Workers and Pages
Copy link

cloudflare-workers-and-pagesbot commentedOct 24, 2024
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:6194229
Status: ✅  Deploy successful!
Preview URL:https://24ecaaa2.pydantic-docs.pages.dev
Branch Preview URL:https://10279-2.pydantic-docs.pages.dev

View logs

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedOct 24, 2024
edited
Loading

CodSpeed Performance Report

Merging#10704 willnot alter performance

Comparing10279-2 (6194229) withmain (aa85c3a)

Summary

✅ 46 untouched benchmarks

@sydney-runkle
Copy link
Contributor

@Viicos, this should be unblocked now :)

@ViicosViicos added the third-party-testsAdd this label on a PR to trigger 3rd party tests labelJan 6, 2025
@ViicosViicos marked this pull request as ready for reviewJanuary 6, 2025 18:55
Comment on lines -761 to -762
assert module.Foo.model_fields['bar'].annotation == typing.Optional[module.Bar[str]]
assert module.Foo.model_fields['bar2'].annotation == typing.Union[int, module.Bar[float]]
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

These assertions are not valid anymore, as theBar[str] class on the annotation is no longer the same that the one we create by callingmodule.Bar[str] here (as it isn't cached anymore).

@github-actionsGitHub Actions
Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  main.py
Project Total 

This report was generated bypython-coverage-comment-action

Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Nice work. Happy to see this move across the line 👍

@sydney-runklesydney-runkle merged commit0b81063 intomainJan 7, 2025
147 checks passed
@sydney-runklesydney-runkle deleted the 10279-2 branchJanuary 7, 2025 14:34
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sydney-runklesydney-runklesydney-runkle approved these changes

Assignees
No one assigned
Labels
relnotes-fixUsed for bugfixes.third-party-testsAdd this label on a PR to trigger 3rd party tests
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

KeyError happening during schema cleaning with generic models KeyError when trying to instantiate BaseModels that depend on each other
2 participants
@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp