]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Report a friendly message if the geometry info is not available
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 21 Sep 2021 15:54:14 +0000 (16:54 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 21 Sep 2021 18:23:34 +0000 (19:23 +0100)
psycopg/psycopg/types/shapely.py
tests/types/test_shapely.py

index 566c65fa6fefa4e7d14b8f2f000edae0820d6524..2686a6e74c55ce767da5f088d98a6acc960bc35b 100644 (file)
@@ -74,6 +74,11 @@ def register_shapely(
 
     """
 
+    # A friendly error warning instead of an AttributeError in case fetch()
+    # failed and it wasn't noticed.
+    if not info:
+        raise TypeError("no info passed. Is the 'postgis' extension loaded?")
+
     info.register(context)
     adapters = context.adapters if context else postgres.adapters
     # Generate and register the text and binary dumper
index fd4447b7799fe863f0795ddcb7a3a32489553799..327fa9c5ddf858b0effbad3b1a3772cb0cdda06f 100644 (file)
@@ -77,6 +77,13 @@ def test_no_adapter(conn):
         conn.execute("SELECT pg_typeof(%s)", [point]).fetchone()[0]
 
 
+def test_no_info_error(conn):
+    from psycopg.types.shapely import register_shapely
+
+    with pytest.raises(TypeError, match="postgis.*extension"):
+        register_shapely(None, conn)
+
+
 def test_with_adapter(shapely_conn):
     SAMPLE_POINT = Point(1.2, 3.4)
     SAMPLE_POLYGON = Polygon([(0, 0), (1, 1), (1, 0)])