Open nix010 opened 1 week ago
Updated: Figured it out ! tests added
I know the commit didn't come with the test but how do I do
import pydantic
from typing import Any
class MyModel(pydantic.BaseModel):
other_field: int = 42
@pydantic.computed_field
@property
def my_field(self) -> str:
return "foo1"
@pydantic.field_serializer("*")
def my_field_serializer(self, value: Any, info: pydantic.FieldSerializationInfo) -> Any:
print(f"{info.field_name} = {value}")
return value
but MyModel
with the SchemaSerializer
and model_fields_schema
like other tests in tests/serializers/test_model.py
All modified and coverable lines are covered by tests :white_check_mark:
:loudspeaker: Thoughts on this report? Let us know!
Comparing nix010:fix-field-serializer-with-computed-field
(cc80ddf) with main
(0e6b377)
✅ 155
untouched benchmarks
please review
The failed CI I think origin from the ruff version ! open to suggestions on fixing those
Looking good so far - I've added a few change requests.
Have you used this version of
pydantic-core
locally to make sure that allpydantic
tests pass, specifically the one included in the OP's issue?
yep.
import pydantic
from typing import Any
class MyModel(pydantic.BaseModel):
other_field: int = 42
@pydantic.computed_field
@property
def my_field(self) -> str:
return "foo1"
@pydantic.field_serializer("*")
def my_field_serializer(self, value: Any, info: pydantic.FieldSerializationInfo) -> Any:
print(f"{info.field_name} = {value}")
return value
print(MyModel().model_dump())
print(MyModel().model_dump_json())
"""
other_field = 42
my_field = foo1
{'other_field': 42, 'my_field': 'foo1'}
other_field = 42
my_field = foo1
{"other_field":42,"my_field":"foo1"}
"""
Change Summary
Related issue number
fix #1348
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @samuelcolvin