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

Bug: OpenAPI schema error when using pydantic.SecretStr with a pydantic.Field #3148

Closed
byte-bot-app bot opened this issue Mar 1, 2024 · 5 comments · Fixed by #3149
Closed

Bug: OpenAPI schema error when using pydantic.SecretStr with a pydantic.Field #3148

byte-bot-app bot opened this issue Mar 1, 2024 · 5 comments · Fixed by #3149
Labels
Bug 🐛 This is something that is not working as expected

Comments

@byte-bot-app
Copy link

byte-bot-app bot commented Mar 1, 2024

Reported by seels in Discord: <#1212255742954971207>:

Hey, all. I'm getting the following error when using a SecretStr attribute (from Pydantic) and accessing /schema/openapi.json: type object 'SecretStr' has no attribute 'item_type'. I've got SecretStr: str in my type_encoders, but that doesn't seem to help.


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@rseeley
Copy link
Contributor

rseeley commented Mar 1, 2024

MCVE:

from litestar import post
from pydantic import BaseModel, Field, SecretStr


class Something(BaseModel):
    password: SecretStr = Field(min_length=8)


@post()
async def something(data: Something) -> Something:
    return data


from litestar.testing import create_test_client

with create_test_client([something]) as client:
    print(client.get('schema/openapi.json').json())

This only happens when password is set to a Field. It works fine when it's just password: SecretStr.

@provinzkraut provinzkraut changed the title Issue from Discord Bug: OpenAPI schema error when using pydantic.SecretStr with a pydantic.Field Mar 1, 2024
@provinzkraut provinzkraut added the Bug 🐛 This is something that is not working as expected label Mar 1, 2024
@provinzkraut
Copy link
Member

@rseeley thanks for reporting! Can you confirm that #3149 fixes this for you?

@rseeley
Copy link
Contributor

rseeley commented Mar 1, 2024

Confirmed, #3149 fixes this issue for me. Thanks for such a quick fix!

Copy link

github-actions bot commented Mar 2, 2024

This issue has been closed in #3149. The change will be included in the upcoming patch release.

Copy link

github-actions bot commented Mar 2, 2024

A fix for this issue has been released in v2.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants