From f075a19e856ced33ddfb0e1330b5c277ddb14bfe Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:10:14 +0200 Subject: [5.0.x] Fixed #35350 -- Fixed save() with pk set on models with GeneratedFields. Thanks Matt Hegarty for the report and Simon Charette and Natalia Bidart for the reviews. Regression in f333e35. Backport of 8b53560eea9f10a1271d3bdf765dc6f969c7d9d5 from main. --- tests/model_fields/test_generatedfield.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/model_fields/test_generatedfield.py b/tests/model_fields/test_generatedfield.py index 641ce591e4..2fbfe3c82a 100644 --- a/tests/model_fields/test_generatedfield.py +++ b/tests/model_fields/test_generatedfield.py @@ -207,6 +207,12 @@ class GeneratedFieldTestMixin: m.refresh_from_db() self.assertEqual(m.field, 8) + def test_save_model_with_pk(self): + m = self.base_model(pk=1, a=1, b=2) + m.save() + m = self._refresh_if_needed(m) + self.assertEqual(m.field, 3) + def test_save_model_with_foreign_key(self): fk_object = Foo.objects.create(a="abc", d=Decimal("12.34")) m = self.base_model(a=1, b=2, fk=fk_object) -- cgit v1.3