From c0726f577caa08e2d6afbbacd3348cb2cb295fff Mon Sep 17 00:00:00 2001 From: reinvantveer Date: Fri, 18 Jun 2021 14:01:03 +0200 Subject: [PATCH] add edge case handling for failed ops or missing objects --- stetl/postgis.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stetl/postgis.py b/stetl/postgis.py index e2dd2f8..a826eae 100755 --- a/stetl/postgis.py +++ b/stetl/postgis.py @@ -148,5 +148,14 @@ def tx_execute(self, sql, parameters=None): except Exception as e: self.e = e log.error("error %s in transaction: %s with parms: %s" % (str(e), str(sql), str(parameters))) + # Return a dummy "-1" row count in the same vein as self.execute() + return -1 + + # Make sure there is a cursor with a row count before returning it, otherwise "return early" + if not hasattr(self, 'cursor'): + return -1 + + if not hasattr(self.cursor, 'rowcount'): + return -1 return self.cursor.rowcount