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)
| 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()) |
nothing calls this directly
no test coverage detected