Skip to content

Commit 3a1d011

Browse files
committed
added support capture queries in async context
1 parent 3e39c10 commit 3a1d011

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/capture_db_queries/decorators.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING, Any
99
from unittest.util import safe_repr
1010

11+
from asgiref.sync import sync_to_async
1112
from django.core.signals import request_started
1213
from django.db import (
1314
connection as db_connection,
@@ -178,6 +179,18 @@ def wrapper_cls(self) -> type[BaseExecutionWrapper]:
178179
return ExplainExecutionWrapper
179180
return BaseExecutionWrapper
180181

182+
async def __aenter__(self):
183+
await sync_to_async(self.__enter__)()
184+
return self
185+
186+
async def __aexit__(
187+
self,
188+
exc_type: type[BaseException] | None,
189+
exc_value: BaseException | None,
190+
traceback: TracebackType | None,
191+
):
192+
await sync_to_async(self.__exit__)(exc_type, exc_value, traceback)
193+
181194
def __enter__(self) -> Self:
182195
log.debug('')
183196

0 commit comments

Comments
 (0)