From: Daniele Varrazzo Date: Tue, 23 Nov 2021 20:23:47 +0000 (+0100) Subject: Improve a few adaptation-related error messages X-Git-Tag: 3.0.5~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c6ef29eae06b240a9c6c8a17060257b433b3a57;p=thirdparty%2Fpsycopg.git Improve a few adaptation-related error messages --- diff --git a/psycopg/psycopg/_adapters_map.py b/psycopg/psycopg/_adapters_map.py index 4fe93c282..6908ecb4f 100644 --- a/psycopg/psycopg/_adapters_map.py +++ b/psycopg/psycopg/_adapters_map.py @@ -218,8 +218,8 @@ class AdaptersMap: return d raise e.ProgrammingError( - f"cannot adapt type {cls.__name__}" - f" to format {PyFormat(format).name}" + f"cannot adapt type {cls.__name__!r} using placeholder '%{format}'" + f" (format: {PyFormat(format).name})" ) def get_dumper_by_oid(self, oid: int, format: pq.Format) -> Type["Dumper"]: diff --git a/psycopg/psycopg/_queries.py b/psycopg/psycopg/_queries.py index eeef76137..b969da86c 100644 --- a/psycopg/psycopg/_queries.py +++ b/psycopg/psycopg/_queries.py @@ -268,8 +268,8 @@ def _split_query(query: bytes, encoding: str = "ascii") -> List[QueryPart]: ) elif ph[-1:] not in b"sbt": raise e.ProgrammingError( - f"only '%s', '%b', '%t' placeholders allowed, got" - f" {m.group(0).decode(encoding)}" + f"only '%s', '%b', '%t' are allowed as placeholders, got" + f" '{m.group(0).decode(encoding)}'" ) # Index or name diff --git a/tests/types/test_shapely.py b/tests/types/test_shapely.py index 0ad2684a8..02bc210d2 100644 --- a/tests/types/test_shapely.py +++ b/tests/types/test_shapely.py @@ -72,7 +72,7 @@ def shapely_conn(conn, svcconn): def test_no_adapter(conn): point = Point(1.2, 3.4) with pytest.raises( - psycopg.ProgrammingError, match="cannot adapt type Point" + psycopg.ProgrammingError, match="cannot adapt type 'Point'" ): conn.execute("SELECT pg_typeof(%s)", [point]).fetchone()[0]