summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2015-11-06 20:18:00 +0100
committerTim Graham <timograham@gmail.com>2015-11-10 12:12:52 -0500
commit5fc9a1b8bd3eb13b7de86ed82ad281d34fa02e8c (patch)
tree4f6f57090a1cbeb7f06f559e7031374cef40bb49 /tests
parent8c8a6d8a3f869ecc4d72b96ddb4760a1b59d5e62 (diff)
[1.8.x] Fixed #25693 -- Prevented data loss with Prefetch and ManyToManyField.
Thanks to Jamie Matthews for finding and explaining the bug. Backport of 4608573788c04fc047da42b4b7b48fdee8136ad3 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/prefetch_related/tests.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py
index f059a6f7ca..c38bc4fb34 100644
--- a/tests/prefetch_related/tests.py
+++ b/tests/prefetch_related/tests.py
@@ -223,6 +223,17 @@ class PrefetchRelatedTests(TestCase):
self.assertIn('prefetch_related', str(cm.exception))
self.assertIn("name", str(cm.exception))
+ def test_m2m_shadow(self):
+ msg = 'to_attr=books conflicts with a field on the Author model.'
+ poems = Book.objects.filter(title='Poems')
+ with self.assertRaisesMessage(ValueError, msg):
+ list(Author.objects.prefetch_related(
+ Prefetch('books', queryset=poems, to_attr='books'),
+ ))
+ # Without the ValueError, a book was deleted due to the implicit
+ # save of reverse relation assignment.
+ self.assertEqual(self.author1.books.count(), 2)
+
class CustomPrefetchTests(TestCase):
@classmethod