Skip to content

Commit 7848210

Browse files
committed
fix failing unit test src/execution_testing/test_types/tests/test_types.py::test_model_copy[Environment]
1 parent 15b5cfd commit 7848210

File tree

1 file changed

+13
-1
lines changed
  • packages/testing/src/execution_testing/base_types

1 file changed

+13
-1
lines changed

packages/testing/src/execution_testing/base_types/pydantic.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,20 @@ class CopyValidateModel(EthereumTestBaseModel):
3131
def copy(self: Self, **kwargs: Any) -> Self:
3232
"""
3333
Create a copy of the model with the updated fields that are validated.
34+
35+
This method preserves the actual field values (including those set via
36+
default_factory) while maintaining the model_fields_set to track which
37+
fields were explicitly set.
3438
"""
35-
return self.__class__(**(self.model_dump(exclude_unset=True) | kwargs))
39+
# Get all current field values, including those set via default_factory
40+
dump_dict = self.model_dump()
41+
# Merge with the updates
42+
dump_dict.update(kwargs)
43+
# Create the new instance
44+
new_instance = self.__class__(**dump_dict)
45+
# Preserve the original model_fields_set, adding any new kwargs
46+
new_instance.__pydantic_fields_set__ = self.model_fields_set | kwargs.keys()
47+
return new_instance
3648

3749

3850
class CamelModel(CopyValidateModel):

0 commit comments

Comments
 (0)