MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / _do_execute

Method _do_execute

asyncpg/connection.py:2002–2080  ·  view source on GitHub ↗
(
        self,
        query,
        executor,
        timeout,
        retry=True,
        *,
        ignore_custom_codec=False,
        record_class=None
    )

Source from the content-addressed store, hash-verified

2000 return result
2001
2002 async def _do_execute(
2003 self,
2004 query,
2005 executor,
2006 timeout,
2007 retry=True,
2008 *,
2009 ignore_custom_codec=False,
2010 record_class=None
2011 ):
2012 if timeout is None:
2013 stmt = await self._get_statement(
2014 query,
2015 None,
2016 record_class=record_class,
2017 ignore_custom_codec=ignore_custom_codec,
2018 )
2019 else:
2020 before = time.monotonic()
2021 stmt = await self._get_statement(
2022 query,
2023 timeout,
2024 record_class=record_class,
2025 ignore_custom_codec=ignore_custom_codec,
2026 )
2027 after = time.monotonic()
2028 timeout -= after - before
2029 before = after
2030
2031 try:
2032 if timeout is None:
2033 result = await executor(stmt, None)
2034 else:
2035 try:
2036 result = await executor(stmt, timeout)
2037 finally:
2038 after = time.monotonic()
2039 timeout -= after - before
2040
2041 except exceptions.OutdatedSchemaCacheError:
2042 # This exception is raised when we detect a difference between
2043 # cached type's info and incoming tuple from the DB (when a type is
2044 # changed by the ALTER TYPE).
2045 # It is not possible to recover (the statement is already done at
2046 # the server's side), the only way is to drop our caches and
2047 # reraise the exception to the caller.
2048 await self.reload_schema_state()
2049 raise
2050 except exceptions.InvalidCachedStatementError:
2051 # PostgreSQL will raise an exception when it detects
2052 # that the result type of the query has changed from
2053 # when the statement was prepared. This may happen,
2054 # for example, after an ALTER TABLE or SET search_path.
2055 #
2056 # When this happens, and there is no transaction running,
2057 # we can simply re-prepare the statement and try once
2058 # again. We deliberately retry only once as this is
2059 # supposed to be a rare occurrence.

Callers 2

__executeMethod · 0.95
_executemanyMethod · 0.95

Calls 4

_get_statementMethod · 0.95
reload_schema_stateMethod · 0.95
is_in_transactionMethod · 0.80

Tested by

no test coverage detected