MCPcopy
hub / github.com/django/django / test_rawsql

Method test_rawsql

tests/queries/test_q.py:383–398  ·  view source on GitHub ↗

RawSQL expressions cause a database error because "price" cannot be replaced by its value. In this case, Q.check() logs a warning and return True.

(self)

Source from the content-addressed store, hash-verified

381 self.assertIs(q.check({"price": Value(10)}), False)
382
383 def test_rawsql(self):
384 """
385 RawSQL expressions cause a database error because "price" cannot be
386 replaced by its value. In this case, Q.check() logs a warning and
387 return True.
388 """
389 q = Q(RawSQL("price > %s", params=(20,), output_field=BooleanField()))
390 with self.assertLogs("django.db.models", "WARNING") as cm:
391 self.assertIs(q.check({"price": 10}), True)
392 self.assertIn(
393 f"Got a database error calling check() on {q!r}: ",
394 cm.records[0].getMessage(),
395 )
396
397 # We must leave the connection in a usable state (#35712).
398 self.assertTrue(connection.is_usable())

Callers

nothing calls this directly

Calls 5

checkMethod · 0.95
QClass · 0.90
RawSQLClass · 0.90
BooleanFieldClass · 0.90
is_usableMethod · 0.45

Tested by

no test coverage detected