(
self,
query,
executor,
timeout,
retry=True,
*,
ignore_custom_codec=False,
record_class=None
)
| 2033 | return result |
| 2034 | |
| 2035 | async def _do_execute( |
| 2036 | self, |
| 2037 | query, |
| 2038 | executor, |
| 2039 | timeout, |
| 2040 | retry=True, |
| 2041 | *, |
| 2042 | ignore_custom_codec=False, |
| 2043 | record_class=None |
| 2044 | ): |
| 2045 | if timeout is None: |
| 2046 | stmt = await self._get_statement( |
| 2047 | query, |
| 2048 | None, |
| 2049 | record_class=record_class, |
| 2050 | ignore_custom_codec=ignore_custom_codec, |
| 2051 | ) |
| 2052 | else: |
| 2053 | before = time.monotonic() |
| 2054 | stmt = await self._get_statement( |
| 2055 | query, |
| 2056 | timeout, |
| 2057 | record_class=record_class, |
| 2058 | ignore_custom_codec=ignore_custom_codec, |
| 2059 | ) |
| 2060 | after = time.monotonic() |
| 2061 | timeout -= after - before |
| 2062 | before = after |
| 2063 | |
| 2064 | try: |
| 2065 | if timeout is None: |
| 2066 | result = await executor(stmt, None) |
| 2067 | else: |
| 2068 | try: |
| 2069 | result = await executor(stmt, timeout) |
| 2070 | finally: |
| 2071 | after = time.monotonic() |
| 2072 | timeout -= after - before |
| 2073 | |
| 2074 | except exceptions.OutdatedSchemaCacheError: |
| 2075 | # This exception is raised when we detect a difference between |
| 2076 | # cached type's info and incoming tuple from the DB (when a type is |
| 2077 | # changed by the ALTER TYPE). |
| 2078 | # It is not possible to recover (the statement is already done at |
| 2079 | # the server's side), the only way is to drop our caches and |
| 2080 | # reraise the exception to the caller. |
| 2081 | await self.reload_schema_state() |
| 2082 | raise |
| 2083 | except exceptions.InvalidCachedStatementError: |
| 2084 | # PostgreSQL will raise an exception when it detects |
| 2085 | # that the result type of the query has changed from |
| 2086 | # when the statement was prepared. This may happen, |
| 2087 | # for example, after an ALTER TABLE or SET search_path. |
| 2088 | # |
| 2089 | # When this happens, and there is no transaction running, |
| 2090 | # we can simply re-prepare the statement and try once |
| 2091 | # again. We deliberately retry only once as this is |
| 2092 | # supposed to be a rare occurrence. |
no test coverage detected