summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Catton <acatton@fusionbox.com>2015-10-05 14:13:14 -0600
committerTim Graham <timograham@gmail.com>2015-10-14 12:21:36 -0700
commitee6785ebea31327bfe473e583b977e03def529ee (patch)
treeaf8fe91b47ef440ad6bdbcaa63624b7191411a69
parent4171d208f4ae79747aa05d255a286ad0a362b9ff (diff)
[1.8.x] Fixed #25506 -- Allowed filtering over a RawSQL annotation.
Co-Authored-By: Gavin Wahl <gwahl@fusionbox.com> Backport of b971c1cd78a0bf831c1c30080089c4a384d037a0 from master
-rw-r--r--django/db/models/lookups.py2
-rw-r--r--docs/releases/1.8.6.txt2
-rw-r--r--tests/expressions/tests.py12
3 files changed, 15 insertions, 1 deletions
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index d6fb607163..d0b30ace1d 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -204,7 +204,7 @@ class BuiltinLookup(Lookup):
lhs_sql = connection.ops.field_cast_sql(
db_type, field_internal_type) % lhs_sql
lhs_sql = connection.ops.lookup_cast(self.lookup_name, field_internal_type) % lhs_sql
- return lhs_sql, params
+ return lhs_sql, list(params)
def as_sql(self, compiler, connection):
lhs_sql, params = self.process_lhs(compiler, connection)
diff --git a/docs/releases/1.8.6.txt b/docs/releases/1.8.6.txt
index acc8a8a93b..44380cded5 100644
--- a/docs/releases/1.8.6.txt
+++ b/docs/releases/1.8.6.txt
@@ -21,3 +21,5 @@ Bugfixes
* Fixed incorrect queries when you have multiple ``ManyToManyField``\s on
different models that have the same field name, point to the same model, and
have their reverse relations disabled (:ticket:`25545`).
+
+* Allowed filtering over a ``RawSQL`` annotation (:ticket:`25506`).
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index 6ba962391a..2d8b17db2d 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -57,6 +57,18 @@ class BasicExpressionsTests(TestCase):
)
self.assertEqual(companies['result'], 2395)
+ def test_annotate_values_filter(self):
+ companies = Company.objects.annotate(
+ foo=RawSQL('%s', ['value']),
+ ).filter(foo='value').order_by('name')
+ self.assertQuerysetEqual(
+ companies, [
+ '<Company: Example Inc.>',
+ '<Company: Foobar Ltd.>',
+ '<Company: Test GmbH>',
+ ],
+ )
+
def test_filter_inter_attribute(self):
# We can filter on attribute relationships on same model obj, e.g.
# find companies where the number of employees is greater