Fix crash when sql execution error has no line number
authorKarl O. Pinc <kop@karlpinc.com>
Sat, 21 Sep 2024 18:54:47 +0000 (13:54 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sat, 21 Sep 2024 18:54:47 +0000 (13:54 -0500)
src/pgwui_sql/views/sql.py

index c169cea023807b4a27127ed624e43191d698f607..b49256befec8ad4ac214186f7e78edc12f84c746 100644 (file)
@@ -168,11 +168,14 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler):
         try:
             cur.execute(stmt_text)
         except psycopg.errors.Error as err:
-            lineno = stmt_text.count(
-                '\n', 0, int(err.diag.statement_position) - 1) + 1
+            stmt_pos = err.diag.statement_position
+            if stmt_pos is None:
+                lineno = ''
+            else:
+                lineno = stmt_text.count('\n', 0, int(stmt_pos) - 1) + 1
             raise sql_ex.ExecutionError(
                 err.diag.severity,
-                lineno,
+                lineno=lineno,
                 descr=err.diag.message_primary,
                 detail=self.format_detail(err, stmt_text))