Skip to content

Commit 8ce4068

Browse files
authored
Fix: merge DEFAULT_ARGS and kwargs in pydantic dict method (#3705)
1 parent b71bd97 commit 8ce4068

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

sqlmesh/utils/pydantic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class PydanticModel(pydantic.BaseModel):
8181
_hash_func_mapping: t.ClassVar[t.Dict[t.Type[t.Any], t.Callable[[t.Any], int]]] = {}
8282

8383
def dict(self, **kwargs: t.Any) -> t.Dict[str, t.Any]:
84-
return super().model_dump(**DEFAULT_ARGS, **kwargs) # type: ignore
84+
kwargs = {**DEFAULT_ARGS, **kwargs}
85+
return super().model_dump(**kwargs) # type: ignore
8586

8687
def json(
8788
self,

tests/utils/test_pydantic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ def private(self) -> str:
5555
model_2_b = TestModel2(name="a")
5656
assert hash(model_2_a) == hash(model_2_b)
5757
assert hash(model_a) != hash(model_2_a)
58+
59+
60+
def test_pydantic_dict_default_args_override() -> None:
61+
class TestModel(PydanticModel):
62+
name: str
63+
64+
assert TestModel(name="foo").dict(by_alias=True)

0 commit comments

Comments
 (0)