diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-09-16 18:10:27 -0400 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-09-17 07:50:08 -0400 |
| commit | 4fcc2883faa8e33152d9e45744354cff35636975 (patch) | |
| tree | 957e44834efe98133950ebf727e5bef7ef25301a /tests/basic/tests.py | |
| parent | 1e7728888dbbff437ad9847c82b84feb81f785df (diff) | |
Refs #27222 -- Restored Model.save()'s refreshing of db_returning fields even if a value is set.
The logic could likely be adjusted to assign the pre_save value in most cases
to avoid the database transit but it could break in subtle ways so it's not
worth the complexity it would require.
Regression in 94680437a45a71c70ca8bd2e68b72aa1e2eff337.
Co-authored-by: Tim Graham <timograham@gmail.com>
Diffstat (limited to 'tests/basic/tests.py')
| -rw-r--r-- | tests/basic/tests.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 38e7278210..38d7d2a3d6 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -215,6 +215,14 @@ class ModelInstanceCreationTests(TestCase): with self.assertNumQueries(1): PrimaryKeyWithFalseyDbDefault().save() + def test_auto_field_with_value_refreshed(self): + """ + An auto field must be refreshed by Model.save() even when a value is + set because the database may return a value of a different type. + """ + a = Article.objects.create(pk="123456", pub_date=datetime(2025, 9, 16)) + self.assertEqual(a.pk, 123456) + class ModelTest(TestCase): def test_objects_attribute_is_only_available_on_the_class_itself(self): |
