From 22a2e97fc30487af89d7c34b753853e7b510083d Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Sat, 4 Apr 2020 20:55:20 +0200 Subject: [3.0.x] Fixed #31420 -- Fixed crash when filtering subquery annotation against a SimpleLazyObject. Thanks Simon Charette for the solution and analysis. Backport of 4237050684427db45ea834fe89d9e11c0520201e from master --- django/db/models/sql/query.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'django/db/models/sql/query.py') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 0e6828b0f1..638161afc2 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -239,7 +239,8 @@ class Query(BaseExpression): @property def output_field(self): if len(self.select) == 1: - return self.select[0].field + select = self.select[0] + return getattr(select, 'target', None) or select.field elif len(self.annotation_select) == 1: return next(iter(self.annotation_select.values())).output_field -- cgit v1.3