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

Inline references if possible when generating schema forjson_schema_input_type#10439

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
Viicos merged 3 commits intomainfrom10434
Sep 19, 2024

Conversation

Viicos
Copy link
Member

@ViicosViicos commentedSep 18, 2024
edited
Loading

Fixes#10434.
Requires#10444.

Previously, the core schema for:

{│'type':'model',│'cls':<class'__main__.Model'>,│'schema': {│   │'type':'model-fields',│   │'fields': {│   │   │'sub': {│   │   │   │'type':'model-field',│   │   │   │'schema': {│   │   │   │   │'type':'function-plain',│   │   │   │   │'function': {'type':'no-info','function':<functionModel.<lambda>at0x7bd0081e94e0>},│   │   │   │   │'metadata': {│   │   │   │   │   │'pydantic_js_functions': [],│   │   │   │   │   │'pydantic_js_annotation_functions': [],│   │   │   │   │   │'pydantic_js_input_core_schema': {'type':'definition-ref','schema_ref':'__main__.Sub:97821927158416'}│   │   │   │   │   },│   │   │   │   │'serialization': {...}│   │   │   │   },│   │   │   │'metadata': {...}│   │   │   }│   │   },│   │'model_name':'Model',│   │'computed_fields': []│   },│'custom_init':False,│'root_model':False,│'config': {'title':'Model'},│'ref':'__main__.Model:97821929019248',│'metadata': {...}}

Withpydantic_js_input_core_schema holding a reference to__main__.Sub:97821927158416 that would not be present in the core schema (because for a plain validator, the source type is not relevant), JSON Schema generation naturally fails (and thankfully only for JSON Schema generation, as thispydantic_js_input_core_schema metadata field is only relevant for JSON Schemas).


My first idea was to add extra logic in the_WalkCoreSchema class to handle this metadata field and include it in schema walking, but this is truly not ideal as we are leaking JSON Schema related logic inside this class (kind of a consequence of our metadata handling which wasn't ideal in the first place, as discussed already :/).

So I decided we should inline refs in the validator class directly, in a safe way for recursive references.

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

mike-optifino reacted with thumbs up emoji
@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelSep 18, 2024
@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedSep 18, 2024
edited
Loading

CodSpeed Performance Report

Merging#10439 willdegrade performances by 12.42%

Comparing10434 (8f3c4b6) withmain (61818e2)

Summary

❌ 1 regressions
✅ 36 untouched benchmarks

⚠️Please fix the performance issues oracknowledge them on CodSpeed.

Benchmarks breakdown

Benchmarkmain10434Change
test_field_validators_serializers2.5 ms2.8 ms-12.42%

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedSep 18, 2024
edited
Loading

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  functional_validators.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.

Great work. Thanks for the nice tests here!

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

cloudflare-workers-and-pagesbot commentedSep 18, 2024
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:8f3c4b6
Status: ✅  Deploy successful!
Preview URL:https://c2e1881d.pydantic-docs.pages.dev
Branch Preview URL:https://10434.pydantic-docs.pages.dev

View logs

@ViicosViicos merged commit3a821f1 intomainSep 19, 2024
61 of 62 checks passed
@ViicosViicos deleted the 10434 branchSeptember 19, 2024 14:15
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.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Plain serializer and validator in Annotated does not work with pydantic model
2 participants
@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp