#Error accessing openapi.json when using SecretStr
1 messages · Page 1 of 1 (latest)
@golden dune
If no response in a reasonable time, ping @Member.
To close, type !solve or byte solve.
Please include an MCVE so that we can reproduce your issue locally.
Heya, possible to share an MCVE? I tried with the following (on current main) it seems to work even without type_encoders={SecretStr: str}
from litestar import post
from pydantic import BaseModel, SecretStr
class Something(BaseModel):
password: SecretStr
@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())
@lucid grove
Please include an MCVE so that we can reproduce your issue locally.
Looks like it's an issue when using pydantic.Field. Your example works for me, but if you change it to the following, it breaks with that error:
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())
@jovial oak seems like something you must know
Oh wow this is interesting.
Okay. Yeah this is a bug. For checking if a string is constrained we do an isinstance check, but unfortunately, SecretStr is not a subclass of str so we don't follow the logic of handling constrained strings, and so we end up with this issue. The same issue will be there for SecretBytes as well.
@golden dune if you'd like to create an issue for this on GitHub, that'd be great 🙂
Also, just to confirm, you're using pydantic v2 right?
use byte 😇
Will do! Thanks!
I am 🙂
GitHub Issue created: https://github.com/litestar-org/litestar/issues/3148
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 o...
That's pretty sick haha.
@stable raven you got a fan
waiting for alc to pick it up
then itll be real cool
https://github.com/Rapptz/discord.py/blob/master/examples/modals/basic.py
Love that idea. I was going to say, it'd be nice if I could've customized the message to remove the "Hey, all" and add the MCVE. But didn't know you made this, Coffee.
I just raised 2 PRs give me a break