Skip to content

Commit ef76bb5

Browse files
authored
Merge pull request #161 from rsinger86/revert/use-copy-instead-of-deepcopy
Revert to copying model state instead of deepcopying it
2 parents 5b0e1e4 + bf4dc67 commit ef76bb5

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

django_lifecycle/model_state.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from __future__ import annotations
2-
3-
from copy import deepcopy
42
from typing import Any
53
from typing import Dict
64
from typing import TYPE_CHECKING
@@ -18,7 +16,7 @@ def __init__(self, initial_state: Dict[str, Any]):
1816

1917
@classmethod
2018
def from_instance(cls, instance: "LifecycleModelMixin") -> ModelState:
21-
state = deepcopy(instance.__dict__)
19+
state = instance.__dict__.copy()
2220

2321
for watched_related_field in instance._watched_fk_model_fields():
2422
state[watched_related_field] = get_value(instance, watched_related_field)

tests/testapp/tests/test_mixin.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ def test_initial_value_if_field_has_changed(self):
7777
user_account.username = "Josephine"
7878
self.assertEqual(user_account.initial_value("username"), "Joe")
7979

80-
def test_initial_value_if_mutable_field_has_changed(self):
81-
data = self.stub_data
82-
UserAccount.objects.create(**data)
83-
user_account = UserAccount.objects.get()
84-
self.assertFalse(user_account.has_changed("configurations"))
85-
user_account.configurations["notifications"] = True
86-
self.assertTrue(user_account.has_changed("configurations"))
87-
self.assertEqual(user_account.initial_value("configurations"), {})
88-
8980
def test_initial_value_if_field_has_not_changed(self):
9081
data = self.stub_data
9182
data["username"] = "Joe"
@@ -213,7 +204,6 @@ def test_has_changed_when_refreshed_from_db(self):
213204
self.assertTrue(user_account.has_changed("username"),
214205
'The initial state should get updated after refreshing the object from db')
215206

216-
217207
def test_has_changed_is_true_if_fk_related_model_field_has_changed(self):
218208
org = Organization.objects.create(name="Dunder Mifflin")
219209
UserAccount.objects.create(**self.stub_data, organization=org)

0 commit comments

Comments
 (0)