Ticket #29214: ticket29214.diff

File ticket29214.diff, 1.5 KB (added by Chetan Khanna, 5 years ago)

Test file

  • tests/update/tests.py

    diff --git a/tests/update/tests.py b/tests/update/tests.py
    index abf4db11d9..e16084d896 100644
    a b  
    11from django.core.exceptions import FieldError
    22from django.db.models import Count, F, Max
     3from django.db.models.expressions import OuterRef, Subquery
    34from django.db.models.functions import Concat, Lower
    45from django.test import TestCase
    56
    6 from .models import A, B, Bar, D, DataPoint, Foo, RelatedPoint
     7from .models import A, B, Bar, C, D, DataPoint, Foo, RelatedPoint
    78
    89
    910class SimpleTest(TestCase):
    class AdvancedTests(TestCase):  
    199200            with self.subTest(annotation=annotation):
    200201                with self.assertRaisesMessage(FieldError, msg):
    201202                    RelatedPoint.objects.annotate(new_name=annotation).update(name=F('new_name'))
     203
     204    def test_update_with_joined_field_outerref(self):
     205        a1 = A.objects.create(x=1)
     206        a2 = A.objects.create(x=3)
     207        a3 = A.objects.create(x=5)
     208        B.objects.bulk_create([
     209            B(a=a1, y=1),
     210            B(a=a2, y=3),
     211            B(a=a3, y=4),
     212        ])
     213        C.objects.bulk_create([
     214            C(y=5),
     215            C(y=10),
     216            C(y=15),
     217        ])
     218        qs = C.objects.filter(y=OuterRef('a__x'))
     219        B.objects.filter(
     220            y__gt=3
     221        ).update(y=Subquery(qs.values('y')[:1]))
     222        self.assertEqual(list(B.objects.filter(y__gt=3).values_list('y', flat=True)), [5])
Back to Top