summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGert Burger <gertburger@gmail.com>2020-08-07 10:02:29 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-12 12:43:42 +0200
commit94ea79be137f3cb30949bf82198e96e094f2650d (patch)
treed268c3a757e7584b96f9d6235eb0ee762b766e12 /tests
parent63300f7e686c2c452763cb512df9abf7734fd588 (diff)
Fixed #31863 -- Prevented mutating model state by copies of model instances.
Regression in bfb746f983aa741afa3709794e70f1e0ab6040b5.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_regress/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/model_regress/tests.py b/tests/model_regress/tests.py
index ba496d1f26..1a4e689b45 100644
--- a/tests/model_regress/tests.py
+++ b/tests/model_regress/tests.py
@@ -1,3 +1,4 @@
+import copy
import datetime
from operator import attrgetter
@@ -256,3 +257,17 @@ class EvaluateMethodTest(TestCase):
dept = Department.objects.create(pk=1, name='abc')
dept.evaluate = 'abc'
Worker.objects.filter(department=dept)
+
+
+class ModelFieldsCacheTest(TestCase):
+ def test_fields_cache_reset_on_copy(self):
+ department1 = Department.objects.create(id=1, name='department1')
+ department2 = Department.objects.create(id=2, name='department2')
+ worker1 = Worker.objects.create(name='worker', department=department1)
+ worker2 = copy.copy(worker1)
+
+ self.assertEqual(worker2.department, department1)
+ # Changing related fields doesn't mutate the base object.
+ worker2.department = department2
+ self.assertEqual(worker2.department, department2)
+ self.assertEqual(worker1.department, department1)