-
Notifications
You must be signed in to change notification settings - Fork 236
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
Consider exclude_none
in computed_field
serialization
#768
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #768 +/- ##
==========================================
- Coverage 93.66% 93.66% -0.01%
==========================================
Files 99 99
Lines 14233 14247 +14
Branches 25 25
==========================================
+ Hits 13331 13344 +13
- Misses 896 897 +1
Partials 6 6
... and 7 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #768 will not alter performanceComparing Summary
|
please review |
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.
LGTM
I can confirm that the This behaviour can easily be replicated with the following code: class Model(BaseModel):
x: int
y: int
@computed_field
def sum(self) -> int:
return self.x + self.y
@computed_field
def none(self) -> None:
return None
m = Model(x=1, y=2)
print(
m.model_dump(exclude_none=True),
m.model_dump_json(exclude_none=True),
sep='\n'
)
# {'x': 1, 'y': 2, 'sum': 3}
# {"x":1,"y":2,"sum":3,"none":null} |
@enricotagliani I can confirm this reproduces in 2.5.3 still, however I cannot reproduce on |
I can still reproduce it with 2.14.6. Is there any kind of workaround for that? |
Related issue: pydantic/pydantic#6549
Selected Reviewer: @adriangb