Skip to content

Commit

Permalink
PR #122 from reinvantveer for #121 defensive DB cursor check
Browse files Browse the repository at this point in the history
add edge case handling for failed ops or missing objects
  • Loading branch information
justb4 authored Jun 18, 2021
2 parents 1d72903 + c0726f5 commit 82c1418
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions stetl/postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 82c1418

Please sign in to comment.