public inbox for [email protected]  
help / color / mirror / Atom feed
From: Murtuza Zabuawala <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM#4858] Allow user to reconnect to DB server when connection is drop
Date: Fri, 10 Apr 2020 19:01:00 +0530
Message-ID: <CAKKotZSE2NN73s2nbnoxsNdZAw-nG7TBEvG3bPGx45TDUica9A@mail.gmail.com> (raw)

Hi,

Upon downloading the csv file, we used the prompt for re-connecting to the
database server when there is a database server connection issue. Currently
the user tries to download CSV and there is a connection issue then it is
showing a python exception error.

Steps:
1) Open query tool
2) Execute -> SELECT 1,2,3
3) Disconnect from server from browser tree
4) Click on Download CSV button

Current: Python exception error
Expected: It should display dialog to reconnect the server.


--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Attachments:

  [application/octet-stream] RM_4858.diff (7.8K, 3-RM_4858.diff)
  download | inline diff:
diff --git a/web/pgadmin/static/js/sqleditor/query_tool_http_error_handler.js b/web/pgadmin/static/js/sqleditor/query_tool_http_error_handler.js
index 97575c1ea..651ff6e91 100644
--- a/web/pgadmin/static/js/sqleditor/query_tool_http_error_handler.js
+++ b/web/pgadmin/static/js/sqleditor/query_tool_http_error_handler.js
@@ -63,6 +63,8 @@ export function handleQueryToolAjaxError(
 
     if(exception.status === 503 && exception.responseJSON.info !== undefined &&
         exception.responseJSON.info == 'CONNECTION_LOST') {
+      // We will display re-connect dialog, no need to display error message again
+      msg = null;
       setTimeout(function() {
         if (stateToSave) {
           handler.saveState(stateToSave, stateParameters);
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index 386a655e4..6d53632a1 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -1370,8 +1370,12 @@ def start_query_download_tool(trans_id):
                 ] = "attachment;filename={0}".format(filename)
 
                 return r
+        except (ConnectionLost, SSHTunnelConnectionLost):
+            raise
         except Exception as e:
-            err_msg = gettext("Error: {0}").format(e.strerror)
+            current_app.logger.error(e)
+            err_msg = "Error: {0}".format(
+                e.strerror if hasattr(e, 'strerror') else str(e))
             return internal_server_error(errormsg=err_msg)
     else:
         return internal_server_error(
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index f5519fcdf..105e4ad30 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -1305,7 +1305,8 @@ define('tools.querytool', [
           let msg = httpErrorHandler.handleQueryToolAjaxError(
             pgAdmin, self, e, null, [], false
           );
-          self.update_msg_history(false, msg);
+          if (msg)
+            self.update_msg_history(false, msg);
         });
     },
 
@@ -2195,9 +2196,10 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, xhr, null, [], false
             );
-            alertify.dlgGetServerPass(
-              gettext('Connect to Server'), msg
-            );
+            if (msg)
+              alertify.dlgGetServerPass(
+                gettext('Connect to Server'), msg
+              );
           });
       },
       /* This function is used to create instance of SQLEditorView,
@@ -2300,10 +2302,10 @@ define('tools.querytool', [
                 msg = httpErrorHandler.handleQueryToolAjaxError(
                   pgAdmin, self, jqx, null, [], false
                 );
-
-                pgBrowser.report_error(
-                  gettext('Error fetching SQL for script: %s.', msg)
-                );
+                if (msg)
+                  pgBrowser.report_error(
+                    gettext('Error fetching SQL for script: %s.', msg)
+                  );
               });
           }
         }
@@ -2484,7 +2486,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_execute_view_data_query', [], true
             );
-            self.update_msg_history(false, msg);
+            if (msg)
+              self.update_msg_history(false, msg);
           });
       },
 
@@ -3237,7 +3240,8 @@ define('tools.querytool', [
             // Enable query tool buttons and cancel button only if query tool
             if(self.is_query_tool)
               self.disable_tool_buttons(false);
-            self.update_msg_history(false, msg);
+            if (msg)
+              self.update_msg_history(false, msg);
           });
       },
 
@@ -3395,7 +3399,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_select_file_handler', stateParams, false
             );
-            alertify.error(msg);
+            if (msg)
+              alertify.error(msg);
             // hide cursor
             $busy_icon_div.removeClass('show_progress');
           });
@@ -3446,7 +3451,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_save_file_handler', stateParams, false
             );
-            alertify.error(msg);
+            if (msg)
+              alertify.error(msg);
           });
       },
 
@@ -3575,7 +3581,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_include_filter', [], true
             );
-            alertify.alert(gettext('Filter By Selection Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Filter By Selection Error'), msg);
           });
       },
 
@@ -3634,7 +3641,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_exclude_filter', [], true
             );
-            alertify.alert(gettext('Filter Exclude Selection Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Filter Exclude Selection Error'), msg);
           });
       },
 
@@ -3672,7 +3680,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_remove_filter', [], true
             );
-            alertify.alert(gettext('Remove Filter Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Remove Filter Error'), msg);
           });
       },
 
@@ -3803,7 +3812,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_set_limit', [], true
             );
-            alertify.alert(gettext('Change limit Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Change limit Error'), msg);
           });
       },
 
@@ -3948,7 +3958,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_cancel_query', [], false
             );
-            alertify.alert(gettext('Cancel Query Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Cancel Query Error'), msg);
           });
       },
 
@@ -4012,7 +4023,6 @@ define('tools.querytool', [
           self.trigger('pgadmin-sqleditor:loading-icon:hide');
         }).fail(function(err) {
           let msg = '';
-
           // Enable the execute button
           $('#btn-flash').prop('disabled', false);
           $('#btn-download').prop('disabled', false);
@@ -4027,7 +4037,9 @@ define('tools.querytool', [
               pgAdmin, self, err, gettext('Download CSV'), [], true
             );
           }
-          alertify.alert(gettext('Download CSV error'), msg);
+          // Check if error message is present
+          if (msg)
+            alertify.alert(gettext('Download CSV error'), msg);
         });
       },
 
@@ -4068,7 +4080,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_auto_rollback', [], true
             );
-            alertify.alert(gettext('Auto Rollback Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Auto Rollback Error'), msg);
           });
       },
 
@@ -4100,7 +4113,8 @@ define('tools.querytool', [
             let msg = httpErrorHandler.handleQueryToolAjaxError(
               pgAdmin, self, e, '_auto_commit', [], true
             );
-            alertify.alert(gettext('Auto Commit Error'), msg);
+            if (msg)
+              alertify.alert(gettext('Auto Commit Error'), msg);
           });
 
       },


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][RM#4858] Allow user to reconnect to DB server when connection is drop
  In-Reply-To: <CAKKotZSE2NN73s2nbnoxsNdZAw-nG7TBEvG3bPGx45TDUica9A@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox