Re: [Django] #36112: DatabaseOperations.format_debug_sql() crashes when query fails to execute on some backends (was: DatabaseOperations.format_debug_sql() crashes on Oracle)

5 views
Skip to first unread message

Django

unread,
Jan 20, 2025, 7:25:24 PM1/20/25
to django-...@googlegroups.com
#36112: DatabaseOperations.format_debug_sql() crashes when query fails to execute
on some backends
-----------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: Tim Graham
Type: Bug | Status: assigned
Component: Testing framework | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Tim Graham):

* cc: Mariusz Felisiak (added)
* summary: DatabaseOperations.format_debug_sql() crashes on Oracle =>
DatabaseOperations.format_debug_sql() crashes when query fails to
execute on some backends

Comment:

This happens on any database backend where
`DatabaseOperations.last_executed_query()` can return `None` (i.e. the
query failed) For example, I observed the same failure
[https://github.com/django/django/blob/337c641abb36b3c2501b14e1290b800831bb20ad/django/db/backends/postgresql/operations.py#L307-L325
on PostgreSQL].

I think there should either be a guard so that a failed query (`sql=None`)
isn't
[https://github.com/django/django/blob/337c641abb36b3c2501b14e1290b800831bb20ad/django/db/backends/utils.py#L145-L163
logged in the first place] or `DatabaseOperations.last_executed_query()`
subclass implementations could fall back to
[https://github.com/django/django/blob/337c641abb36b3c2501b14e1290b800831bb20ad/django/db/backends/base/operations.py#L265-L287
BaseDatabaseOperations.last_executed_query()] rather than returning
`None`.

It may be useful to see the failing query in the logs, but I'm open to
other opinions about this. The pre-
d8f093908c504ae0dbc39d3f5231f7d7920dde37 behavior is to log `(0.000)
NONE; args=<actual params>; ALIAS=DEFAULT`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36112#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages