diff options
author | Ian Foote <python@ian.feete.org> | 2020-11-15 22:43:47 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-11-27 20:42:04 +0100 |
commit | 8b040e3cbbb2e81420e777afc3ca48a1c8f4dd5a (patch) | |
tree | 32ed8b5456c9ce569643a1ebb34491a1c9b6fa01 /tests/update | |
parent | e46ca51c249677c52e04db28fc0c60ae1948b3b2 (diff) | |
download | django-8b040e3cbbb2e81420e777afc3ca48a1c8f4dd5a.tar.gz |
Fixed #25534, Fixed #31639 -- Added support for transform references in expressions.
Thanks Mariusz Felisiak and Simon Charette for reviews.
Diffstat (limited to 'tests/update')
-rw-r--r-- | tests/update/tests.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/tests/update/tests.py b/tests/update/tests.py index 90844ccb6f..588db40de6 100644 --- a/tests/update/tests.py +++ b/tests/update/tests.py @@ -2,9 +2,10 @@ import unittest from django.core.exceptions import FieldError from django.db import IntegrityError, connection, transaction -from django.db.models import Count, F, Max -from django.db.models.functions import Concat, Lower +from django.db.models import CharField, Count, F, IntegerField, Max +from django.db.models.functions import Abs, Concat, Lower from django.test import TestCase +from django.test.utils import register_lookup from .models import A, B, Bar, D, DataPoint, Foo, RelatedPoint, UniqueNumber @@ -154,6 +155,13 @@ class AdvancedTests(TestCase): with self.assertRaisesMessage(FieldError, msg): Bar.objects.update(m2m_foo='whatever') + def test_update_transformed_field(self): + A.objects.create(x=5) + A.objects.create(x=-6) + with register_lookup(IntegerField, Abs): + A.objects.update(x=F('x__abs')) + self.assertCountEqual(A.objects.values_list('x', flat=True), [5, 6]) + def test_update_annotated_queryset(self): """ Update of a queryset that's been annotated. @@ -194,14 +202,18 @@ class AdvancedTests(TestCase): 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')) + with register_lookup(CharField, Lower): + for annotation in ( + F('data__name'), + F('data__name__lower'), + 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')) @unittest.skipUnless( |