mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #10811 -- Made assigning unsaved objects to FK, O2O, and GFK raise ValueError.
This prevents silent data loss. Thanks Aymeric Augustin for the initial patch and Loic Bistuer for the review.
This commit is contained in:
committed by
Tim Graham
parent
4f72e5f03a
commit
5643a3b51b
@@ -66,8 +66,10 @@ class ManyToOneRegressionTests(TestCase):
|
||||
|
||||
# Creation using keyword argument and unsaved related instance (#8070).
|
||||
p = Parent()
|
||||
c = Child(parent=p)
|
||||
self.assertTrue(c.parent is p)
|
||||
with self.assertRaisesMessage(ValueError,
|
||||
'Cannot assign "%r": "%s" instance isn\'t saved in the database.'
|
||||
% (p, Child.parent.field.rel.to._meta.object_name)):
|
||||
Child(parent=p)
|
||||
|
||||
# Creation using attname keyword argument and an id will cause the
|
||||
# related object to be fetched.
|
||||
|
||||
Reference in New Issue
Block a user