From 9ae4362becbde31dc9cc31ae0b1db969e7007431 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 27 Apr 2017 21:30:37 -0400 Subject: [PATCH] Refs #16187 -- Stopped compiling query compilers during lookup rhs processing. Lookup right hand side processing was compiling query compilers which happened to work by chance as SQLCompiler defines a as_sql() method with two optional parameters albeit it doesn't expect the same type of arguments. --- django/db/models/lookups.py | 6 ------ django/db/models/sql/query.py | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index 48e68d0b8b..2a10721eb2 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -89,12 +89,6 @@ class Lookup: value = Value(value, output_field=self.lhs.output_field) value = self.apply_bilateral_transforms(value) value = value.resolve_expression(compiler.query) - # Due to historical reasons there are a couple of different - # ways to produce sql here. get_compiler is likely a Query - # instance and as_sql just something with as_sql. Finally the value - # can of course be just plain Python value. - if hasattr(value, 'get_compiler'): - value = value.get_compiler(connection=connection) if hasattr(value, 'as_sql'): sql, params = compiler.compile(value) return '(' + sql + ')', params diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index a1c1c4be38..d105408253 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -989,6 +989,9 @@ class Query: clone.clear_ordering(True) return clone + def as_sql(self, compiler, connection): + return self.get_compiler(connection=connection).as_sql() + def prepare_lookup_value(self, value, lookups, can_reuse, allow_joins=True): # Default lookup if none given is exact. used_joins = []