From 03049fb8d96ccd1f1ed0285486103542de42faba Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 17 Oct 2017 11:28:00 +0800 Subject: Refs #28010 -- Allowed reverse related fields in SELECT FOR UPDATE .. OF. Thanks Adam Chidlow for polishing the patch. --- tests/filtered_relation/tests.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tests/filtered_relation') diff --git a/tests/filtered_relation/tests.py b/tests/filtered_relation/tests.py index 4bae2216bf..2596dcbdc2 100644 --- a/tests/filtered_relation/tests.py +++ b/tests/filtered_relation/tests.py @@ -1,4 +1,4 @@ -from django.db import connection +from django.db import connection, transaction from django.db.models import Case, Count, F, FilteredRelation, Q, When from django.test import TestCase from django.test.testcases import skipUnlessDBFeature @@ -62,6 +62,20 @@ class FilteredRelationTests(TestCase): (self.book4, self.author1), ], lambda x: (x, x.author_join)) + @skipUnlessDBFeature('has_select_for_update', 'has_select_for_update_of') + def test_select_related_foreign_key_for_update_of(self): + with transaction.atomic(): + qs = Book.objects.annotate( + author_join=FilteredRelation('author'), + ).select_related('author_join').select_for_update(of=('self',)).order_by('pk') + with self.assertNumQueries(1): + self.assertQuerysetEqual(qs, [ + (self.book1, self.author1), + (self.book2, self.author2), + (self.book3, self.author2), + (self.book4, self.author1), + ], lambda x: (x, x.author_join)) + def test_without_join(self): self.assertSequenceEqual( Author.objects.annotate( -- cgit v1.3