summaryrefslogtreecommitdiff
path: root/tests/one_to_one
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-09-19 13:36:38 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-09-19 20:27:53 +0200
commitc3904deb919823af577adf5d9d35e9c113eb8289 (patch)
treef8d22a2af5f600c7989a991bbdc62cf93d29e784 /tests/one_to_one
parenta4b80e242162a7d6ac2337a2a621a82027c549b7 (diff)
downloaddjango-c3904deb919823af577adf5d9d35e9c113eb8289.tar.gz
Fixed #25160 (again) -- Moved data loss check on reverse relations.
Moved data loss check when assigning to a reverse one-to-one relation on an unsaved instance to Model.save(). This is exactly the same change as e4b813c but for reverse relations.
Diffstat (limited to 'tests/one_to_one')
-rw-r--r--tests/one_to_one/tests.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py
index 49da8dfbd2..1319cf0d9b 100644
--- a/tests/one_to_one/tests.py
+++ b/tests/one_to_one/tests.py
@@ -373,13 +373,15 @@ class OneToOneTests(TestCase):
"""
p = Place()
b = UndergroundBar.objects.create()
- msg = (
- 'Cannot assign "<UndergroundBar: UndergroundBar object>": "Place" '
- 'instance isn\'t saved in the database.'
- )
+
+ # Assigning a reverse relation on an unsaved object is allowed.
+ p.undergroundbar = b
+
+ # However saving the object is not allowed.
+ msg = "save() prohibited to prevent data loss due to unsaved related object 'place'."
with self.assertNumQueries(0):
with self.assertRaisesMessage(ValueError, msg):
- p.undergroundbar = b
+ b.save()
def test_nullable_o2o_delete(self):
u = UndergroundBar.objects.create(place=self.p1)