1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Refs #33308 -- Avoided passing None to RawSQL's params.

Passing None to params causes errors in determining the data type on
psycopg3.
This commit is contained in:
Florian Apolloner 2022-12-02 10:43:49 +01:00 committed by Mariusz Felisiak
parent 2fecf99ade
commit 3e3b7f691b

View File

@ -164,12 +164,12 @@ class TestQuery(SimpleTestCase):
class TestQueryNoModel(TestCase):
def test_rawsql_annotation(self):
query = Query(None)
sql = "%s IS NULL"
sql = "%s = 1"
# Wrap with a CASE WHEN expression if a database backend (e.g. Oracle)
# doesn't support boolean expression in SELECT list.
if not connection.features.supports_boolean_expr_in_select_clause:
sql = f"CASE WHEN {sql} THEN 1 ELSE 0 END"
query.add_annotation(RawSQL(sql, (None,), BooleanField()), "_check")
query.add_annotation(RawSQL(sql, (1,), BooleanField()), "_check")
result = query.get_compiler(using=DEFAULT_DB_ALIAS).execute_sql(SINGLE)
self.assertEqual(result[0], 1)
@ -183,8 +183,7 @@ class TestQueryNoModel(TestCase):
def test_q_annotation(self):
query = Query(None)
check = ExpressionWrapper(
Q(RawSQL("%s IS NULL", (None,), BooleanField()))
| Q(Exists(Item.objects.all())),
Q(RawSQL("%s = 1", (1,), BooleanField())) | Q(Exists(Item.objects.all())),
BooleanField(),
)
query.add_annotation(check, "_check")