Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Aug 7, 2024

When a model is defined in a separate module and the core schema building was deferred (because defer_build was set or because it failed to evaluate an annotation), GenerateSchema._model_schema would use the wrong instance to evaluate the __pydantic_extra__ annotation (so the wrong types namespace was used, resulting in an unhelpful NameError).

Fixes #10069.

Change Summary

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

…tances

When a model is defined in a separate module and the core schema building
was deferred (because `defer_build` was set or because it failed to evaluate
an annotation), `GenerateSchema._model_schema` would use the wrong instance
to evaluate the `__pydantic_extra__` annotation (so the wrong types namespace
was used, resulting in an unhelpful `NameError`).
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Aug 7, 2024
@Viicos Viicos changed the title Fix evaluation of __pydantic_extra__ annotation in specific circums Fix evaluation of __pydantic_extra__ annotation in specific circumstances Aug 7, 2024
Copy link

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a6c8fa4
Status: ✅  Deploy successful!
Preview URL: https://0cdd1a5c.pydantic-docs.pages.dev
Branch Preview URL: https://10069-extras-eval.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Aug 7, 2024

CodSpeed Performance Report

Merging #10070 will not alter performance

Comparing 10069-extras-eval (a6c8fa4) with main (ac0cf36)

Summary

✅ 17 untouched benchmarks

Copy link
Contributor

github-actions bot commented Aug 7, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _generate_schema.py 705
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Awesome find. Looks great!

Wish github would offer a more clear diff here - seems like it's challenged with cases like this one.

@sydney-runkle sydney-runkle merged commit facbf93 into main Aug 7, 2024
62 checks passed
@sydney-runkle sydney-runkle deleted the 10069-extras-eval branch August 7, 2024 11:35
@Viicos
Copy link
Member Author

Viicos commented Aug 7, 2024

@sydney-runkle, https://github.com/pydantic/pydantic/pull/10070/files?diff=split&w=1 can help (hide whitespace enabled).

@sydney-runkle
Copy link
Contributor

@Viicos,

Oh nice! I didn't know about the whitespace version. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failing core schema generation when importing a model with a mock schema from another module
2 participants