summaryrefslogtreecommitdiff
path: root/tests/update
diff options
context:
space:
mode:
authorcan <cansarigol@derinbilgi.com.tr>2019-06-27 22:13:48 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-06-28 07:55:32 +0200
commitf03b7bd11461e8b525c27d5344f8cd3a21c9565e (patch)
treefc75221f0682058c80ca72fafe068e5d821ab7e9 /tests/update
parentfb54aca5404a95bcd50d6d9010c34584965e3176 (diff)
Fixed #28408 -- Added error message when updating with annotated expressions on joined fields.
Co-Authored-By: Simon Charette <charette.s@gmail.com>
Diffstat (limited to 'tests/update')
-rw-r--r--tests/update/tests.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/tests/update/tests.py b/tests/update/tests.py
index 8cb4d11f75..abf4db11d9 100644
--- a/tests/update/tests.py
+++ b/tests/update/tests.py
@@ -1,5 +1,6 @@
from django.core.exceptions import FieldError
from django.db.models import Count, F, Max
+from django.db.models.functions import Concat, Lower
from django.test import TestCase
from .models import A, B, Bar, D, DataPoint, Foo, RelatedPoint
@@ -182,16 +183,19 @@ class AdvancedTests(TestCase):
# Update where annotation is used for filtering
qs = DataPoint.objects.annotate(related_count=Count('relatedpoint'))
self.assertEqual(qs.filter(related_count=1).update(value='Foo'), 1)
- # Update where annotation is used in update parameters
- # #26539 - This isn't forbidden but also doesn't generate proper SQL
- # qs = RelatedPoint.objects.annotate(data_name=F('data__name'))
- # updated = qs.update(name=F('data_name'))
- # self.assertEqual(updated, 1)
# Update where aggregation annotation is used in update parameters
qs = RelatedPoint.objects.annotate(max=Max('data__value'))
- msg = (
- 'Aggregate functions are not allowed in this query '
- '(name=Max(Col(update_datapoint, update.DataPoint.value))).'
- )
+ msg = 'Joined field references are not permitted in this query'
with self.assertRaisesMessage(FieldError, msg):
qs.update(name=F('max'))
+
+ def test_update_with_joined_field_annotation(self):
+ msg = 'Joined field references are not permitted in this query'
+ for annotation in (
+ F('data__name'),
+ Lower('data__name'),
+ Concat('data__name', 'data__value'),
+ ):
+ with self.subTest(annotation=annotation):
+ with self.assertRaisesMessage(FieldError, msg):
+ RelatedPoint.objects.annotate(new_name=annotation).update(name=F('new_name'))