mirror of https://github.com/django/django.git
This commit is contained in:
parent
80fe2f4391
commit
33c06ca0da
|
@ -122,7 +122,7 @@ class Lookup(Expression):
|
||||||
# Ensure expression is wrapped in parentheses to respect operator
|
# Ensure expression is wrapped in parentheses to respect operator
|
||||||
# precedence but avoid double wrapping as it can be misinterpreted
|
# precedence but avoid double wrapping as it can be misinterpreted
|
||||||
# on some backends (e.g. subqueries on SQLite).
|
# on some backends (e.g. subqueries on SQLite).
|
||||||
if sql and sql[0] != "(":
|
if not isinstance(value, Value) and sql and sql[0] != "(":
|
||||||
sql = "(%s)" % sql
|
sql = "(%s)" % sql
|
||||||
return sql, params
|
return sql, params
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1366,6 +1366,12 @@ class LookupTests(TestCase):
|
||||||
[stock_1, stock_2],
|
[stock_1, stock_2],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_lookup_direct_value_rhs_unwrapped(self):
|
||||||
|
with self.assertNumQueries(1) as ctx:
|
||||||
|
self.assertIs(Author.objects.filter(GreaterThan(2, 1)).exists(), True)
|
||||||
|
# Direct values on RHS are not wrapped.
|
||||||
|
self.assertIn("2 > 1", ctx.captured_queries[0]["sql"])
|
||||||
|
|
||||||
|
|
||||||
class LookupQueryingTests(TestCase):
|
class LookupQueryingTests(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue