Hi,

PFA patch to fix the issue where users were not able to see notices in
Messages tab incase of error, I have updated redmine with sample code to
reproduce the issue.

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/tools/sqleditor/__init__.py 
b/web/pgadmin/tools/sqleditor/__init__.py
index 2975d8f..b1ca3b8 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -760,6 +760,14 @@ def poll(trans_id):
         status, result = conn.poll(
             formatted_exception_msg=True, no_result=True)
         if not status:
+            messages = conn.messages()
+            if messages and len(messages) > 0:
+                additional_messages = ''.join(messages)
+                result = '{0}\n{1}\n\n{2}'.format(
+                             additional_messages,
+                             gettext('******* Error *******'),
+                             result
+                )
             return internal_server_error(result)
         elif status == ASYNC_OK:
             status = 'Success'
@@ -800,10 +808,11 @@ def poll(trans_id):
                             conn.manager.version
                         )
 
-                        SQL = render_template("/".join([template_path,
-                                                        'nodes.sql']),
-                                              tid=command_obj.obj_id,
-                                              has_oids=True)
+                        SQL = render_template(
+                            "/".join([template_path,'nodes.sql']),
+                            tid=command_obj.obj_id,
+                            has_oids=True
+                        )
                         # rows with attribute not_null
                         colst, rset = conn.execute_2darray(SQL)
                         if not colst:
@@ -973,7 +982,8 @@ def fetch(trans_id, fetch_all=None):
 
     return make_json_response(
         data={
-            'status': status, 'result': result,
+            'status': status,
+            'result': result,
             'has_more_rows': has_more_rows,
             'rows_fetched_from': rows_fetched_from,
             'rows_fetched_to': rows_fetched_to
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py 
b/web/pgadmin/utils/driver/psycopg2/__init__.py
index f26209b..5acfb32 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -1333,6 +1333,7 @@ Failed to reset the connection to the server due to 
following error:
             )
         )
 
+        is_error = False
         try:
             status = self._wait_timeout(self.conn)
         except psycopg2.Error as pe:
@@ -1343,12 +1344,18 @@ Failed to reset the connection to the server due to 
following error:
                     self.conn_id[5:]
                 )
             errmsg = self._formatted_exception_msg(pe, formatted_exception_msg)
-            return False, errmsg
+            is_error = True
 
         if self.conn.notices and self.__notices is not None:
             while self.conn.notices:
                 self.__notices.append(self.conn.notices.pop(0)[:])
 
+        # We also need to fetch notices before we return from function in case
+        # of any Exception, To avoid code duplication we will return after
+        # fetching the notices in case of any Exception
+        if is_error:
+            return False, errmsg
+
         result = None
         self.row_count = 0
         self.column_info = None

Reply via email to