summaryrefslogtreecommitdiff
path: root/tests
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:28:22 +0200
commit1abd177696ef72843557980fbdd352176ed2800e (patch)
tree4c3296df31a7fa911a8d8399678054b47b4fa8a7 /tests
parenta0ce708c1cfa29c13d7334bb27d9c91f570307e8 (diff)
[1.8.x] 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. Backport of c3904de from master
Diffstat (limited to 'tests')
-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 b71ee0645a..727ff11efd 100644
--- a/tests/one_to_one/tests.py
+++ b/tests/one_to_one/tests.py
@@ -371,13 +371,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)