May as well trap out-of-memory all the time
authorKarl O. Pinc <kop@karlpinc.com>
Wed, 2 Oct 2024 16:57:00 +0000 (11:57 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Wed, 2 Oct 2024 17:02:42 +0000 (12:02 -0500)
src/pgwui_sql/exceptions.py
src/pgwui_sql/views/sql.py

index 310a76ec10df8eaf96c1fe4d668a51bf6ae2dc38..6e9459b69cd36910454011ac4d4f0363d334cacc 100644 (file)
@@ -86,14 +86,11 @@ class CSVError(SQLError):
 
 class MemoryError(SQLError):
     '''
-    Error raised when we run out of memory generating on-screen results
+    Error raised when we run out of memory
 
     descr  More description of the error
     detail Extra HTML describing the error
     '''
-    def __init__(self,
-                 descr=("Can't collect results for on-screen display"
-                        '-- try downloading instead'),
-                 detail=''):
+    def __init__(self, descr='', detail=''):
         super().__init__('Webserver out of memory',
                          '', descr=descr, detail=detail)
index 5dcabc9e2349bd59e978dbfcc37b758f18885b54..23b38044d6be227063bdd7872e8fc627a49d15fb 100644 (file)
@@ -337,18 +337,24 @@ class SQLResultsHandler(pgwui_core.core.SessionDBHandler):
         if cur.statusmessage is None:
             raise sql_ex.NoStatementsError(descr='No SQL statements executed')
 
-        if self.uf['download']:
-            try:
-                self.make_download(cur)
-            except csv.Error as ex:
-                raise sql_ex.CSVError(descr=f'The csv module reports: {ex}')
-        else:
-            try:
+        try:
+            if self.uf['download']:
+                try:
+                    self.make_download(cur)
+                except csv.Error as ex:
+                    raise sql_ex.CSVError(
+                        descr=f'The csv module reports: {ex}')
+            else:
                 self.make_sql_results(cur)
-            except MemoryError:
-                self.sql_results = []
-                gc.collect()
+        except MemoryError:
+            self.sql_results = []
+            gc.collect()
+            if self.uf['download_as'] == MANY_FILES_VALUE:
                 raise sql_ex.MemoryError()
+            else:
+                raise sql_ex.MemoryError(
+                    ("Can't collect results for on-screen display"
+                     '-- try downloading instead'))
 
     def factory(self, ue):
         '''Make a db loader function from an UploadEngine.