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

JSON serialisation error with Secret types union. #9231

Closed
1 task done
KasperZutterman opened this issue Apr 12, 2024 · 2 comments · Fixed by #9240
Closed
1 task done

JSON serialisation error with Secret types union. #9231

KasperZutterman opened this issue Apr 12, 2024 · 2 comments · Fixed by #9240
Assignees
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@KasperZutterman
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

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

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'>

Python, Pydantic & OS Version

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
@KasperZutterman KasperZutterman added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 12, 2024
@sydney-runkle sydney-runkle added this to the 2.7 fixes milestone Apr 13, 2024
@sydney-runkle
Copy link
Member

@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!

@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Apr 13, 2024
@sydney-runkle sydney-runkle self-assigned this Apr 14, 2024
@sydney-runkle
Copy link
Member

^^ I've opened #9240 to address this issue :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants