diff roundup/backends/back_postgresql.py @ 8302:82a26ea1afdf

issue2551376: Fix tracebacks in item templates
author Ralf Schlatterbeck <rsc@runtux.com>
date Wed, 26 Feb 2025 11:24:13 +0100
parents cfa7d43a3658
children 45ec660eb7f7
line wrap: on
line diff
--- a/roundup/backends/back_postgresql.py	Wed Feb 19 12:50:07 2025 +0100
+++ b/roundup/backends/back_postgresql.py	Wed Feb 26 11:24:13 2025 +0100
@@ -116,7 +116,7 @@
         #
         # Database name is any character sequence not including a " or
         # whitespace. Arguably both are allowed by:
-        # 
+        #
         #  https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
         #
         # with suitable quoting but ... really.
@@ -170,7 +170,7 @@
         #
         # Database name is any character sequence not including a " or
         # whitespace. Arguably both are allowed by:
-        # 
+        #
         #  https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
         #
         # with suitable quoting but ... really.
@@ -560,6 +560,16 @@
             self.cursor.execute('DROP SEQUENCE _%s_ids' % cn)
             self.cursor.execute('CREATE SEQUENCE _%s_ids' % cn)
 
+    def getnode (self, classname, nodeid, fetch_multilinks=True):
+        """ For use of savepoint see 'Class' below """
+        self.sql('savepoint sp')
+        try:
+            getnode = rdbms_common.Database.getnode
+            return getnode(self, classname, nodeid, fetch_multilinks)
+        except psycopg2.errors.DataError as err:
+            self.sql('rollback to savepoint sp')
+            raise hyperdb.HyperdbValueError(str (err).split('\n')[0])
+
 
 class PostgresqlClass:
     order_by_null_values = '(%s is not NULL)'
@@ -567,7 +577,34 @@
 
 
 class Class(PostgresqlClass, rdbms_common.Class):
-    pass
+    """ We re-raise database-specific data errors as HyperdbValueError
+        Note that we re-use the savepoint so that at most one savepoint
+        is used.
+    """
+
+    def filter(self, *args, **kw):
+        self.db.sql('savepoint sp')
+        try:
+            return rdbms_common.Class.filter(self, *args, **kw)
+        except psycopg2.errors.DataError as err:
+            self.db.sql('rollback to savepoint sp')
+            raise hyperdb.HyperdbValueError(str (err).split('\n')[0])
+
+    def filter_iter(self, *args, **kw):
+        self.db.sql('savepoint sp')
+        try:
+            return rdbms_common.Class.filter_iter(self, *args, **kw)
+        except psycopg2.errors.DataError as err:
+            self.db.sql('rollback to savepoint sp')
+            raise hyperdb.HyperdbValueError(str (err).split('\n')[0])
+
+    def is_retired(self, nodeid):
+        self.db.sql('savepoint sp')
+        try:
+            return rdbms_common.Class.is_retired(self, nodeid)
+        except psycopg2.errors.DataError as err:
+            self.db.sql('rollback to savepoint sp')
+            raise hyperdb.HyperdbValueError (str (err).split('\n')[0])
 
 
 class IssueClass(PostgresqlClass, rdbms_common.IssueClass):

Roundup Issue Tracker: http://roundup-tracker.org/