Skip to content

Commit

Permalink
don't flag that a model has changes unless the values have actually c…
Browse files Browse the repository at this point in the history
…hanged from the originals
  • Loading branch information
dannosaur committed Nov 6, 2023
1 parent d395b7b commit 2ee9e9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pydantic_changedetect/changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def __setattr__(self, name, value) -> None: # noqa: ANN001
if name in self_compat.model_fields and name not in self.model_original:
self.model_original[name] = self.__dict__[name]
super().__setattr__(name, value)
self.model_self_changed_fields.add(name)
if self.model_original[name] != value:
self.model_self_changed_fields.add(name)

def __getstate__(self) -> Dict[str, Any]:
state = super().__getstate__()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def test_set_changed_state():
assert obj.model_changed_fields == {"id"}


def test_values_did_not_change():
obj = Something(id=1)
assert not obj.model_has_changed
obj.id = 1
assert not obj.model_has_changed
assert obj.model_changed_fields == set()


def test_set_changed_state_with_fixed_original():
obj = Something(id=1)

Expand Down

0 comments on commit 2ee9e9c

Please sign in to comment.