mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #25296 -- Prevented model related object cache pollution when create() fails due to an unsaved object.
This commit is contained in:
		| @@ -643,6 +643,9 @@ class Model(six.with_metaclass(ModelBase)): | ||||
|                 # constraints aren't supported by the database, there's the | ||||
|                 # unavoidable risk of data corruption. | ||||
|                 if obj and obj.pk is None: | ||||
|                     # Remove the object from a related instance cache. | ||||
|                     if not field.remote_field.multiple: | ||||
|                         delattr(obj, field.remote_field.get_cache_name()) | ||||
|                     raise ValueError( | ||||
|                         "save() prohibited to prevent data loss due to " | ||||
|                         "unsaved related object '%s'." % field.name | ||||
|   | ||||
		Reference in New Issue
	
	Block a user