Skip to content

Commit 3d2924a

Browse files
committed
Avoid use of logging context when no loggers are configured
1 parent 8c29bbd commit 3d2924a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

asyncpg/connection.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ async def execute(self, query: str, *args, timeout: float=None) -> str:
343343
self._check_open()
344344

345345
if not args:
346-
with self._time_and_log(query, args, timeout):
346+
if self._query_loggers:
347+
with self._time_and_log(query, args, timeout):
348+
result = await self._protocol.query(query, timeout)
349+
else:
347350
result = await self._protocol.query(query, timeout)
348351
return result
349352

@@ -1876,7 +1879,16 @@ async def __execute(
18761879
timeout=timeout,
18771880
)
18781881
timeout = self._protocol._get_timeout(timeout)
1879-
with self._time_and_log(query, args, timeout):
1882+
if self._query_loggers:
1883+
with self._time_and_log(query, args, timeout):
1884+
result, stmt = await self._do_execute(
1885+
query,
1886+
executor,
1887+
timeout,
1888+
record_class=record_class,
1889+
ignore_custom_codec=ignore_custom_codec,
1890+
)
1891+
else:
18801892
result, stmt = await self._do_execute(
18811893
query,
18821894
executor,

0 commit comments

Comments
 (0)