We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
A PydanticSerializationError is raised when attempting model_dump_json() on a model containing a union of Secret types.
model_dump_json()
Error: pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic.types.Secret'>
pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic.types.Secret'>
from pydantic import BaseModel, Secret class Base(BaseModel): x: Secret[int] | Secret[str] model = Base(x=1) print(model.model_dump()) # No error print(model.model_dump_json()) # pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic.types.Secret'>
pydantic version: 2.7.0 pydantic-core version: 2.18.1 pydantic-core build: profile=release pgo=true install path: /Users/kasperzutterman/.pyenv/versions/3.12.1/envs/pydantic-3.12/lib/python3.12/site-packages/pydantic python version: 3.12.1 (main, Feb 2 2024, 09:13:09) [Clang 15.0.0 (clang-1500.1.0.2.5)] platform: macOS-14.4.1-arm64-arm-64bit related packages: typing_extensions-4.9.0 commit: unknown
The text was updated successfully, but these errors were encountered:
@KasperZutterman,
Thanks for reporting this! Definitely something that we want to fix. Will release a fix for this early next week with 2.7.1!
Sorry, something went wrong.
Secret
^^ I've opened #9240 to address this issue :).
sydney-runkle
Successfully merging a pull request may close this issue.
Initial Checks
Description
A PydanticSerializationError is raised when attempting
model_dump_json()
on a model containing a union of Secret types.Error:
pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic.types.Secret'>
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: