]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
feat: use version() as __build_version__ for pq python implementation
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 15 Aug 2022 11:41:01 +0000 (13:41 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 15 Aug 2022 13:41:04 +0000 (15:41 +0200)
Having __build_version__ to be null makes version checking needlessly
convoluted and version() has to be used anyway as fallback.

psycopg/psycopg/_pipeline.py
psycopg/psycopg/pq/__init__.py
psycopg/psycopg/pq/pq_ctypes.py
tests/fix_pq.py
tests/pq/test_pq.py

index e1593d1ba045c907a025b3dc0fc4c25bc7f908b5..ac7d25efe722963e531226f2018d1d1a7332c22b 100644 (file)
@@ -63,7 +63,8 @@ class BasePipeline:
             # Support only depends on the libpq functions available in the pq
             # wrapper, not on the database version.
             pq_version = pq.__build_version__ or pq.version()
-            BasePipeline._is_supported = pq_version >= 140000
+            # Pipeline support broken in libpq 14.5 (#350)
+            BasePipeline._is_supported = pq_version >= 140000 and pq_version != 140005
         return BasePipeline._is_supported
 
     def _enter_gen(self) -> PQGen[None]:
index 3cf58cef1cc47e542bbbaf4b8d1317c02de93750..d5180b1b6682b7def219682b23c3e95a23ce26cc 100644 (file)
@@ -11,7 +11,7 @@ implementation-dependant but all the implementations share the same interface.
 
 import os
 import logging
-from typing import Callable, List, Optional, Type
+from typing import Callable, List, Type
 
 from . import abc
 from .misc import ConninfoOption, PGnotify, PGresAttDesc
@@ -27,12 +27,12 @@ __impl__: str
 Possible values include ``python``, ``c``, ``binary``.
 """
 
-__build_version__: Optional[int]
+__build_version__: int
 """The libpq version the C package was built with.
 
 A number in the same format of `~psycopg.ConnectionInfo.server_version`
 representing the libpq used to build the speedup module (``c``, ``binary``) if
-available. `!None` if `__impl__` is ``python``.
+available.
 
 Certain features might not be available if the built version is too old.
 """
@@ -98,7 +98,7 @@ def import_from_libpq() -> None:
         Conninfo = module.Conninfo
         Escaping = module.Escaping
         PGcancel = module.PGcancel
-        __build_version__ = getattr(module, "__build_version__", None)
+        __build_version__ = module.__build_version__
     elif impl:
         raise ImportError(f"requested psycopg implementation '{impl}' unknown")
     else:
index ae3deed78933d7b60b666a462e5bfde2e4373583..d0174adc695cdce35251983d329f2deafb96242d 100644 (file)
@@ -1047,3 +1047,5 @@ import ssl  # noqa
 # disable libcrypto setup in libpq, so it won't stomp on the callbacks
 # that have already been set up
 impl.PQinitOpenSSL(1, 0)
+
+__build_version__ = version()
index af14c7d42ece2d48d8f0e5cfd436c93181ca3a4d..a17d2854f4f47e1ffb2f3a326f29b5bea3dfd446 100644 (file)
@@ -81,7 +81,7 @@ def setpgenv(monkeypatch):
 
 @pytest.fixture
 def trace(libpq):
-    pqver = pq.__build_version__ or pq.version()
+    pqver = pq.__build_version__
     if pqver < 140000:
         pytest.skip(f"trace not available on libpq {pqver}")
     if sys.platform != "linux":
index d344d121365d0b9bcb049017bd6e2577a1fb1b99..8cceace56f4ef79ee4b2b415184e664aed3e92e7 100644 (file)
@@ -15,12 +15,7 @@ def test_version():
 
 
 def test_build_version():
-    if pq.__impl__ == "python":
-        assert pq.__build_version__ is None
-    elif pq.__impl__ in ["c", "binary"]:
-        assert pq.__build_version__ and pq.__build_version__ >= 70400
-    else:
-        assert False, f"unexpected libpq implementation: {pq.__impl__}"
+    assert pq.__build_version__ and pq.__build_version__ >= 70400
 
 
 @pytest.mark.skipif("not os.environ.get('PSYCOPG_TEST_WANT_LIBPQ_BUILD')")