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

exclude attribute of fields is ignored in model_dump #9465

Closed
1 task done
devkral opened this issue May 21, 2024 · 2 comments
Closed
1 task done

exclude attribute of fields is ignored in model_dump #9465

devkral opened this issue May 21, 2024 · 2 comments
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation

Comments

@devkral
Copy link

devkral commented May 21, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

At least when specifying your own exclude in model_dump the exclude attribute of fields is ignored.
I worked around by injecting the field names manually in exclude.

It would be nice if the exclude attribute could be honored even when the exclude parameter is specified in model_dump

Note: I use FieldInfo directly, see the edgy db system or better the PR:

dymmond/edgy#89

Note2: it would be even better to have the exclude attribute for ComputedFieldInfo, despite the unlogic in it (computed_field is used for including a method in a model_dump). But for library authors it improves the usability

Example Code

No response

Python, Pydantic & OS Version

pydantic version: 2.7.1
        pydantic-core version: 2.18.2
        pydantic-core build: profile=release pgo=true
                 install path: /home/alex/.local/share/hatch/env/virtual/edgy/dfnzc1V2/test/lib/python3.12/site-packages/pydantic
               python version: 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]
                     platform: Linux-6.8.9-arch1-2-x86_64-with-glibc2.39
             related packages: typing_extensions-4.11.0 pydantic-settings-2.2.1 mypy-1.9.0 pydantic-extra-types-2.7.0
                       commit: unknown
@devkral devkral added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels May 21, 2024
@sydney-runkle
Copy link
Member

Hi @devkral,

Could you please provide a minimally reproducible example for this? Happy to help once we have a more clear idea there.

@sydney-runkle
Copy link
Member

Going to close this as not planned for now, but happy to reopen with an MRE!

@sydney-runkle sydney-runkle closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
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 pending Awaiting a response / confirmation
Projects
None yet
Development

No branches or pull requests

2 participants