diff options
| author | Ilya Bass <ilya.bass@pathai.com> | 2022-10-20 15:14:35 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-21 09:10:14 +0100 |
| commit | 798e38c2b9c46ab72e2ee8c33dc822f01b194b1e (patch) | |
| tree | 32e558e0f86e04f9198646bffa11c08198dfe43c /django/db/backends/utils.py | |
| parent | c0a93d39411004300dfda2deb3dc093b69ac6368 (diff) | |
Fixed #31090 -- Logged transaction management queries.
Thanks to Petter Strandmark for the original idea and Mariusz Felisiak
for advice during the DjangoConUS 2022 Sprint!
Diffstat (limited to 'django/db/backends/utils.py')
| -rw-r--r-- | django/db/backends/utils.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py index d505cd7904..df6532e81f 100644 --- a/django/db/backends/utils.py +++ b/django/db/backends/utils.py @@ -144,6 +144,35 @@ class CursorDebugWrapper(CursorWrapper): ) +@contextmanager +def debug_transaction(connection, sql): + start = time.monotonic() + try: + yield + finally: + if connection.queries_logged: + stop = time.monotonic() + duration = stop - start + connection.queries_log.append( + { + "sql": "%s" % sql, + "time": "%.3f" % duration, + } + ) + logger.debug( + "(%.3f) %s; args=%s; alias=%s", + duration, + sql, + None, + connection.alias, + extra={ + "duration": duration, + "sql": sql, + "alias": connection.alias, + }, + ) + + def split_tzname_delta(tzname): """ Split a time zone name into a 3-tuple of (name, sign, offset). |
