From: Daniele Varrazzo Date: Tue, 7 Jun 2022 03:02:07 +0000 (+0200) Subject: refactor(crdb): drop crdb_version; use server_version instead X-Git-Tag: 3.1~49^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e31891f4a49f56405ce9902db6b7be401cd848c0;p=thirdparty%2Fpsycopg.git refactor(crdb): drop crdb_version; use server_version instead The server_version returned by CRDB is a misleading dummy. The version tested is reported as 13.0 but certain features are more akin to different versions (e.g. lack of range support and different behaviour w.r.t. unknown/text adaptation). --- diff --git a/psycopg/psycopg/crdb/connection.py b/psycopg/psycopg/crdb/connection.py index a52bad03e..998ba4720 100644 --- a/psycopg/psycopg/crdb/connection.py +++ b/psycopg/psycopg/crdb/connection.py @@ -157,15 +157,11 @@ class CrdbConnectionInfo(ConnectionInfo): return "CockroachDB" @property - def crdb_version(self) -> int: + def server_version(self) -> int: """ Return the CockroachDB server version connected. - Return None if the server is not CockroachDB, else return a number in - the PostgreSQL format (e.g. 21.2.10 -> 200210) - - Assume all the connections are on the same db: return a cached result on - following calls. + Return a number in the PostgreSQL format (e.g. 21.2.10 -> 200210) """ sver = self.parameter_status("crdb_version") if not sver: diff --git a/tests/crdb/test_conninfo.py b/tests/crdb/test_conninfo.py index 6fc36d049..f1a5473ac 100644 --- a/tests/crdb/test_conninfo.py +++ b/tests/crdb/test_conninfo.py @@ -7,8 +7,8 @@ def test_vendor(conn): assert conn.info.vendor == "CockroachDB" -def test_crdb_version(conn): - assert conn.info.crdb_version > 200000 +def test_server_version(conn): + assert conn.info.server_version > 200000 def test_backend_pid(conn): diff --git a/tests/test_conninfo.py b/tests/test_conninfo.py index e9d959fb8..a8111702e 100644 --- a/tests/test_conninfo.py +++ b/tests/test_conninfo.py @@ -212,6 +212,7 @@ class TestConnectionInfo: assert tz and isinstance(tz, str) assert tz == conn.execute("show timezone").fetchone()[0] + @pytest.mark.crdb("skip") def test_server_version(self, conn): assert conn.info.server_version == conn.pgconn.server_version diff --git a/tools/update_oids.py b/tools/update_oids.py index 6812446f4..777f5e3a4 100755 --- a/tools/update_oids.py +++ b/tools/update_oids.py @@ -75,7 +75,7 @@ def get_version_comment(conn: Connection) -> List[str]: version = f"{num // 10000}.{num % 100}" elif conn.info.vendor == "CockroachDB": assert isinstance(conn, CrdbConnection) - num = conn.info.crdb_version + num = conn.info.server_version version = f"{num // 10000}.{num % 10000 // 100}.{num % 100}" else: raise NotImplementedError(f"unexpected vendor: {conn.info.vendor}")