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

validate_python / model_validate: exclude #1095

Open
mustafa0x opened this issue Nov 27, 2023 · 1 comment
Open

validate_python / model_validate: exclude #1095

mustafa0x opened this issue Nov 27, 2023 · 1 comment
Assignees

Comments

@mustafa0x
Copy link

Lazy loaded orm fields are loaded inadvertently by model_validate (which calls validate_python). I'd like to be able to exclude fields from model_validate.

Previously discussed here pydantic/pydantic#6861.

With the release of pydantic v2, is it possible to load a model and exclude certain fields when loading using the new model_validate method? I was hoping the new context parameter was able to achieve this, but it looks this does not quite do what I was thinking.

(cross post of pydantic/pydantic#8192)

@mustafa0x
Copy link
Author

mustafa0x commented Nov 28, 2023

fastapi's response_model_exclude requires this too.

You can also use the path operation decorator parameters response_model_include and response_model_exclude.

They take a set of str with the name of the attributes to include (omitting the rest) or to exclude (including the rest).

This can be used as a quick shortcut if you have only one Pydantic model and want to remove some data from the output.

It's used a fair bit too: https://github.com/search?q=language%3Apython+%2Fresponse_model_exclude%3D%5C%7B%2F&type=code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants