mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
[1.8.x] Fixed #24508 -- Made annotations commutative
Backport of 127b3873d0 from master
This commit is contained in:
@@ -99,6 +99,14 @@ class NonAggregateAnnotationTestCase(TestCase):
|
||||
sum_rating=Sum('rating')
|
||||
).filter(sum_rating=F('nope')))
|
||||
|
||||
def test_combined_annotation_commutative(self):
|
||||
book1 = Book.objects.annotate(adjusted_rating=F('rating') + 2).get(pk=self.b1.pk)
|
||||
book2 = Book.objects.annotate(adjusted_rating=2 + F('rating')).get(pk=self.b1.pk)
|
||||
self.assertEqual(book1.adjusted_rating, book2.adjusted_rating)
|
||||
book1 = Book.objects.annotate(adjusted_rating=F('rating') + None).get(pk=self.b1.pk)
|
||||
book2 = Book.objects.annotate(adjusted_rating=None + F('rating')).get(pk=self.b1.pk)
|
||||
self.assertEqual(book1.adjusted_rating, book2.adjusted_rating)
|
||||
|
||||
def test_update_with_annotation(self):
|
||||
book_preupdate = Book.objects.get(pk=2)
|
||||
Book.objects.annotate(other_rating=F('rating') - 1).update(rating=F('other_rating'))
|
||||
|
||||
Reference in New Issue
Block a user