Fix BEGIN leaking into SQL panel when using DatabaseCache store#2397
Fix BEGIN leaking into SQL panel when using DatabaseCache store#2397marcosalvesdev wants to merge 2 commits into
Conversation
|
👋🏼 Hey you! Guys, the tox tests for SQLite are failing. I investigated it and found that the behavior expected in tests/panels/test_sql.py, which assumed that boolean parameters for non-PostgreSQL databases would be introduced in Django 6.2, was already introduced in 6.1. So I opened issue #2398. I was thinking about fixing it in this PR, but I would like to hear your thoughts first to make sure my findings are correct and the fix suggested in the issue is the right one. |
…it-leak-sql-panel
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
Fixed by #2403. Thanks @matthiask 👍🏼 |
Description
Fixes #2338
When using CacheStore with Django's DatabaseCache backend, the transaction.atomic() calls used internally by the toolbar to persist its own data were emitting BEGIN/COMMIT (or SAVEPOINT/RELEASE SAVEPOINT inside a
test transaction) into the SQL panel. These commands carry no table name, so the existing
SKIP_TOOLBAR_QUERIES filter — which works by matching known toolbar table names in the SQL string — could
never suppress them.
The fix introduces a ContextVar (sql_recording, default True) in tracking.py and a context manager
no_sql_recording() that sets it to False for the duration of the toolbar's own persistence operations. The
decision logic in NormalCursorMixin._record() now consults this flag: when sql_recording=False, only
queries that explicitly reference a known toolbar table (and where SKIP_TOOLBAR_QUERIES=False) are recorded — preserving the existing opt-in behavior while suppressing table-less control commands unconditionally.
no_sql_recording() is applied in two places:
by DatabaseStore
Checklist:
AI/LLM Usage