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(pydantic): OpenAPI schema generation for Pydantic private attributes (#3150) #3151

Merged
merged 3 commits into from Mar 2, 2024

Conversation

provinzkraut
Copy link
Member

Fix a bug that caused a NameError when trying to resolve forward references in Pydantic private fields.

Although we respected private fields in Pydantic and didn't include them in the schema, we still tried to extract their type annotation. This was fixed by not relying on typing.get_type_hints to get the type information, but instead using Pydantic's own APIs, allowing us to only extract information about the types of fields we're interested in.

Fixes #3150.

Copy link

codecov bot commented Mar 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.23%. Comparing base (1332983) to head (61628a8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3151      +/-   ##
==========================================
- Coverage   98.26%   98.23%   -0.03%     
==========================================
  Files         320      320              
  Lines       14417    14427      +10     
  Branches     2319     2323       +4     
==========================================
+ Hits        14167    14173       +6     
- Misses        109      113       +4     
  Partials      141      141              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@provinzkraut provinzkraut force-pushed the fix-pydantic-private-attribute-access branch from 5206da6 to 9e064ef Compare March 2, 2024 11:00
@provinzkraut provinzkraut force-pushed the fix-pydantic-private-attribute-access branch from e2439c8 to 83b6088 Compare March 2, 2024 11:05
@provinzkraut provinzkraut force-pushed the fix-pydantic-private-attribute-access branch from 02018b6 to 61628a8 Compare March 2, 2024 11:19
Copy link

sonarcloud bot commented Mar 2, 2024

Copy link

github-actions bot commented Mar 2, 2024

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3151

@provinzkraut provinzkraut merged commit 961d3eb into main Mar 2, 2024
21 checks passed
@provinzkraut provinzkraut deleted the fix-pydantic-private-attribute-access branch March 2, 2024 13:29
euri10 pushed a commit to euri10/litestar that referenced this pull request Mar 4, 2024
…tes (litestar-org#3150) (litestar-org#3151)

* Fix OpenAPI schema generation for Pydantic v2 constrained secrets
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.

Bug: pydantic PrivateAttr fields are inspected for type hints
2 participants