From: Daniele Varrazzo Date: Fri, 12 Apr 2024 22:36:36 +0000 (+0200) Subject: refactor: check if cancel safe is implemented via capabilities X-Git-Tag: 3.2.0~41^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2b38b9946f0703c4dddbee003f18e8f2a7642c8a;p=thirdparty%2Fpsycopg.git refactor: check if cancel safe is implemented via capabilities --- diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index 9701770d8..12c06993a 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -32,6 +32,7 @@ from ._encodings import pgconn_encoding from .generators import notifies from .transaction import Transaction from .cursor import Cursor +from ._capabilities import capabilities from .server_cursor import ServerCursor from ._connection_base import BaseConnection, CursorRow, Notify @@ -277,8 +278,7 @@ class Connection(BaseConnection[Row]): if not self._should_cancel(): return - # TODO: replace with capabilities.has_safe_cancel after merging #782 - if pq.__build_version__ >= 170000: + if capabilities.has_cancel_safe(): try: waiting.wait_conn( self._cancel_gen(timeout=timeout), interval=_WAIT_INTERVAL diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index beb4c8714..096213a1b 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -29,6 +29,7 @@ from ._encodings import pgconn_encoding from .generators import notifies from .transaction import AsyncTransaction from .cursor_async import AsyncCursor +from ._capabilities import capabilities from .server_cursor import AsyncServerCursor from ._connection_base import BaseConnection, CursorRow, Notify @@ -294,8 +295,7 @@ class AsyncConnection(BaseConnection[Row]): if not self._should_cancel(): return - # TODO: replace with capabilities.has_safe_cancel after merging #782 - if pq.__build_version__ >= 170000: + if capabilities.has_cancel_safe(): try: await waiting.wait_conn_async( self._cancel_gen(timeout=timeout), interval=_WAIT_INTERVAL