From a8c70abfdf68fc841556b317a558c5dcf192b3a6 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 7 Jul 2017 13:01:38 -0400 Subject: [PATCH] Added a test for QuerySet.update() with a ManyToManyField. --- tests/update/models.py | 1 + tests/update/tests.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/tests/update/models.py b/tests/update/models.py index bfcc29bee9..b56dd2258e 100644 --- a/tests/update/models.py +++ b/tests/update/models.py @@ -46,3 +46,4 @@ class Foo(models.Model): class Bar(models.Model): foo = models.ForeignKey(Foo, models.CASCADE, to_field='target') + m2m_foo = models.ManyToManyField(Foo, related_name='m2m_foo') diff --git a/tests/update/tests.py b/tests/update/tests.py index 55a8e24c6a..ba7ffd5c88 100644 --- a/tests/update/tests.py +++ b/tests/update/tests.py @@ -139,6 +139,15 @@ class AdvancedTests(TestCase): bar_qs.update(foo=b_foo) self.assertEqual(bar_qs[0].foo_id, b_foo.target) + def test_update_m2m_field(self): + msg = ( + 'Cannot update model field ' + ' ' + '(only non-relations and foreign keys permitted).' + ) + with self.assertRaisesMessage(FieldError, msg): + Bar.objects.update(m2m_foo='whatever') + def test_update_annotated_queryset(self): """ Update of a queryset that's been annotated.