Support exclude_if in computed fields#12748
Merged
Viicos merged 7 commits intopydantic:mainfrom Mar 17, 2026
Merged
Conversation
andresliszt
commented
Jan 28, 2026
| raise PydanticUserError( | ||
| 'exclude_if set in the computed_field decorator and in the annotated type', | ||
| code='invalid-annotated-type', | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
is this status code correct?
andresliszt
commented
Jan 28, 2026
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
Author
|
please review |
davidhewitt
reviewed
Jan 31, 2026
Collaborator
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, implementation seems mostly great to me, couple of small thoughts...
9d9012e to
88c732a
Compare
5 tasks
88c732a to
1cf1573
Compare
exclude_if in computed fields
Viicos
approved these changes
Mar 17, 2026
Member
Viicos
left a comment
There was a problem hiding this comment.
Thanks @andresliszt, that's a nice one!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
This PR aims to support
serialization_exclude_ifin computed fields. This PR adds the ability to exclude the computed field both by passing a direct argument to the decorator,exclude_if(following the same naming convention we use for regular fields), and also if it receives anAnnotatedas in the example described in the linked issue.Related issue number
Fixes #12690
Checklist
Selected Reviewer: @Viicos