Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Support exclude_if at field level#10961
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
fd789eb
to537d0dd
Compareplease review |
andreslisztNov 24, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
So committing (temporary) this file is necessary when building from an open PR on pydantic-core, right?
codspeed-hqbot commentedNov 24, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#10961 willnot alter performanceComparing Summary
|
@@ -11,7 +11,7 @@ git fetch --tags | |||
pip install -r requirements.txt | |||
# Install the version of pydantic from the current branch, not the released version used by fastapi | |||
pip uninstall -y pydantic | |||
pip uninstall -y pydantic pydantic-core# TODO: pydantic-core is temporal here | |||
cd ..&& pip install.&&cd fastapi |
andreslisztNov 24, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Had to addpydantic-core
, I think this has to be here for installingpydantic-core
from branch to work --- Do I keep it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This file is removed onmain
iirc, so should matter anymore 👍
Coverage reportClick to see where and how coverage changed
This report was generated bypython-coverage-comment-action |
emosenkis commentedFeb 10, 2025
It would be great if the callback could also receive a serialization context (my use case is excluding fields based on the |
We'll be revisiting this before the v2.11 release 👍 |
joshorr commentedMar 31, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Curious what the status of this is. I am assuming it did not make it out in v2.11; do you know when it might come out? I've been looking forward to this for a while! 😃 |
Curious too!@sydney-runkle Let me know if you guys still need this, to update the PR if necessary |
lokhman commentedApr 30, 2025
@andresliszt@sydney-runkle We (users) need it very much :) Let's push it forward! |
I'll get back on this shortly! |
Viicos left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hi@andresliszt sorry for the delay. Are you willing to continue working on this? Left some comments, it is mostly in good shape (lets keep it at the field level for now, we can later improve this to be onmodel_dump()
etc), but some relatively simple conflicts will need to be resolved.
@@ -950,6 +961,7 @@ def Field( # noqa: C901 | |||
description: Human-readable description. | |||
examples: Example values for this field. | |||
exclude: Whether to exclude the field from the model serialization. | |||
exclude_if: Callable that determines whether to exclude a field during serialization based on its value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
exclude_if:Callablethatdetermineswhethertoexcludeafieldduringserializationbasedonitsvalue. | |
exclude_if:Acallablethatdetermineswhethertoexcludeafieldduringserializationbasedonitsvalue. |
@@ -784,6 +791,7 @@ def Field( | |||
description: str | None = _Unset, | |||
examples: list[Any] | None = _Unset, | |||
exclude: bool | None = _Unset, | |||
exclude_if: Callable[[Any], bool] | None = _Unset, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
For this overload (default
set) and the one fordefault_factory
set, we can reuse the type variable to get proper type checking:
exclude_if:Callable[[_T],bool]=_Unset
@@ -11,7 +11,7 @@ git fetch --tags | |||
pip install -r requirements.txt | |||
# Install the version of pydantic from the current branch, not the released version used by fastapi | |||
pip uninstall -y pydantic | |||
pip uninstall -y pydantic pydantic-core# TODO: pydantic-core is temporal here | |||
cd ..&& pip install.&&cd fastapi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This file is removed onmain
iirc, so should matter anymore 👍
@@ -116,6 +117,7 @@ class FieldInfo(_repr.Representation): | |||
description: The description of the field. | |||
examples: List of examples of the field. | |||
exclude: Whether to exclude the field from the model serialization. | |||
exclude_if: Callable that determines whether to exclude a field during serialization based on its value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
exclude_if:Callablethatdetermineswhethertoexcludeafieldduringserializationbasedonitsvalue. | |
exclude_if:Acallablethatdetermineswhethertoexcludeafieldduringserializationbasedonitsvalue. |
@@ -1057,6 +1057,7 @@ def _generate_td_field_schema( | |||
return core_schema.typed_dict_field( | |||
common_field['schema'], | |||
required=False if not field_info.is_required() else required, | |||
exclude_if=field_info.exclude_if, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Will need to be updated according to mypydantic-core
PR review
Hello ! I commit to have it This week, best regards |
Uh oh!
There was an error while loading.Please reload this page.
Change Summary
Adds support for pydantic side
exclude_if
. This PR points to thepydantic
-core version in the open PR added in the related issue.Related issue number
pydantic/pydantic-core#1535
Checklist
Selected Reviewer:@sydney-runkle