Upgrade from psycopg2 to psycopg3; drop python <= v3.5, add v3.8-v3.11
authorKarl O. Pinc <kop@karlpinc.com>
Fri, 23 Feb 2024 20:25:46 +0000 (14:25 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Fri, 23 Feb 2024 20:25:46 +0000 (14:25 -0600)
setup.py
src/pgwui_upload_core/views/upload.py
tox.ini

index 83aa618383f8222c7f405d33b1053fa027f4aee9..7ed85db8085f5d36cb081da6996b71abdbc0f852 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -115,10 +115,12 @@ setup(
         # Specify the Python versions you support here. In particular, ensure
         # that you indicate whether you support Python 2, Python 3 or both.
         'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
         'Programming Language :: Python :: 3.6',
         'Programming Language :: Python :: 3.7',
+        'Programming Language :: Python :: 3.8',
+        'Programming Language :: Python :: 3.9',
+        'Programming Language :: Python :: 3.10',
+        'Programming Language :: Python :: 3.11',
     ],
 
     # What does your project relate to?
@@ -159,7 +161,7 @@ setup(
         'attrs',
         'markupsafe',
         'pgwui_common',
-        'psycopg2',
+        'psycopg',
         'pyramid',
     ],
 
index 97459ad65384bf8ff0132b78252b7692ff85e2aa..47042cf5fb64238dfa423e1b897d1384c6589a68 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015, 2018, 2020, 2021 The Meme Factory, Inc.
+# Copyright (C) 2015, 2018, 2020, 2021, 2024 The Meme Factory, Inc.
 # http://www.karlpinc.com/
 
 # This file is part of PGWUI_Upload_Core.
@@ -27,8 +27,7 @@
 import attr
 import logging
 import markupsafe
-import psycopg2.errorcodes
-from psycopg2 import ProgrammingError
+import psycopg.errors
 
 from pgwui_core.core import (
     UploadNullFileInitialPost,
@@ -89,7 +88,7 @@ class SaveLine(DataLineProcessor, ParameterExecutor):
         ue             UploadEngine instance
         uh             UploadHandler instance
         insert_stmt    Statement used to insert into db.
-                       (psycopg2 formatted for substituion)
+                       (psycopg3 formatted for substituion)
         '''
         super(SaveLine, self).__init__(ue, uh)
         self.insert_stmt = insert_stmt
@@ -157,25 +156,22 @@ class BaseTableUploadHandler(TabularFileUploadHandler):
                  '            ON (pg_namespace.oid = pg_class.relnamespace)'
                  '  WHERE pg_class.oid = %s::REGCLASS::OID'),
                 (qualified_table,))
-        except ProgrammingError as err:
-            pgcode = err.pgcode
-            if pgcode == psycopg2.errorcodes.INVALID_SCHEMA_NAME:
-                raise upload_ex.MissingSchemaError(
-                    'No such schema',
-                    err.diag.message_primary,)
-            elif pgcode == psycopg2.errorcodes.UNDEFINED_TABLE:
-                raise upload_ex.MissingTableError(
-                    'No such table or view',
-                    err.diag.message_primary,
-                    ('<p>Hint: Check spelling, database permissions, '
-                     ' or try qualifying the'
-                     ' table name with a schema name</p>'))
-            elif pgcode == psycopg2.errorcodes.INSUFFICIENT_PRIVILEGE:
-                raise upload_ex.InsufficientPrivilegeError(
-                    'Your PostgreSQL login has insufficient privileges',
-                    err.diag.message_primary)
-            else:
-                raise
+        except psycopg.errors.INVALID_SCHEMA_NAME as err:
+            raise upload_ex.MissingSchemaError(
+                'No such schema',
+                err.diag.message_primary,)
+        except psycopg.errors.UNDEFINED_TABLE as err:
+            raise upload_ex.MissingTableError(
+                'No such table or view',
+                err.diag.message_primary,
+                ('<p>Hint: Check spelling, database permissions, '
+                 ' or try qualifying the'
+                 ' table name with a schema name</p>'))
+        except psycopg.errors.INSUFFICIENT_PRIVILEGE as err:
+            raise upload_ex.InsufficientPrivilegeError(
+                'Your PostgreSQL login has insufficient privileges',
+                err.diag.message_primary)
+
         return self.cur.fetchone()
 
     def resolve_table(self, qualified_table):
diff --git a/tox.ini b/tox.ini
index 1ea296a2a460f32fc13878c4c9c0bfea9abaea5e..0bbee65a054417444a398827e77019248d095fc0 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,14 @@
 [tox]
-envlist = py{34,35,36,37}
+envlist = py{36,37,38,39,310,311}
 
 [testenv]
 basepython =
-    py34: python3.4
-    py35: python3.5
     py36: python3.6
     py37: python3.7
+    py38: python3.8
+    py39: python3.9
+    py310: python3.10
+    py311: python3.11
 deps =
     check-manifest
     cmarkgfm