1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

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 94680437a4.

Co-authored-by: Tim Graham <timograham@gmail.com>
This commit is contained in:
Simon Charette
2025-09-16 18:10:27 -04:00
committed by Jacob Walls
parent 1e7728888d
commit 4fcc2883fa
3 changed files with 24 additions and 4 deletions

View File

@@ -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):