Ticket #28408: unclear_f_annotations_error_message_failing_test.diff

File unclear_f_annotations_error_message_failing_test.diff, 1.0 KB (added by Kevin Marsh, 7 years ago)
  • tests/annotations/tests.py

    diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
    index 36e6754..7a16cc7 100644
    a b class NonAggregateAnnotationTestCase(TestCase):  
    261261        book_postupdate = Book.objects.get(pk=self.b2.pk)
    262262        self.assertEqual(book_preupdate.rating - 1, book_postupdate.rating)
    263263
     264    def test_joined_f_update_errors_are_clear_when_annotating(self):
     265        error_msg = 'Joined field references are not permitted in this query'
     266        with self.assertRaisesMessage(FieldError, error_msg):
     267            Book.objects.update(name=F('contact__name'))
     268
     269        with self.assertRaisesMessage(FieldError, error_msg):
     270            Book.objects.annotate(
     271                contact_name=F('contact__name')
     272            ).update(name=F('contact_name'))
     273
    264274    def test_annotation_with_m2m(self):
    265275        books = Book.objects.annotate(author_age=F('authors__age')).filter(pk=self.b1.pk).order_by('author_age')
    266276        self.assertEqual(books[0].author_age, 34)
Back to Top