mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #35425 -- Avoided INSERT with force_update and explicit pk.
Affected models where the primary key field is defined with a default or db_default, such as UUIDField.
This commit is contained in:
		| @@ -1088,6 +1088,7 @@ class Model(AltersData, metaclass=ModelBase): | |||||||
|         if ( |         if ( | ||||||
|             not raw |             not raw | ||||||
|             and not force_insert |             and not force_insert | ||||||
|  |             and not force_update | ||||||
|             and self._state.adding |             and self._state.adding | ||||||
|             and ( |             and ( | ||||||
|                 (meta.pk.default and meta.pk.default is not NOT_PROVIDED) |                 (meta.pk.default and meta.pk.default is not NOT_PROVIDED) | ||||||
|   | |||||||
| @@ -186,6 +186,12 @@ class ModelInstanceCreationTests(TestCase): | |||||||
|         with self.assertNumQueries(1): |         with self.assertNumQueries(1): | ||||||
|             PrimaryKeyWithDefault().save() |             PrimaryKeyWithDefault().save() | ||||||
|  |  | ||||||
|  |     def test_save_primary_with_default_force_update(self): | ||||||
|  |         # An UPDATE attempt is made if explicitly requested. | ||||||
|  |         obj = PrimaryKeyWithDefault.objects.create() | ||||||
|  |         with self.assertNumQueries(1): | ||||||
|  |             PrimaryKeyWithDefault(uuid=obj.pk).save(force_update=True) | ||||||
|  |  | ||||||
|     def test_save_primary_with_db_default(self): |     def test_save_primary_with_db_default(self): | ||||||
|         # An UPDATE attempt is skipped when a primary key has db_default. |         # An UPDATE attempt is skipped when a primary key has db_default. | ||||||
|         with self.assertNumQueries(1): |         with self.assertNumQueries(1): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user