diff --git a/docs/en_US/release_notes_4_23.rst b/docs/en_US/release_notes_4_23.rst index 427e93b39..025957b4b 100644 --- a/docs/en_US/release_notes_4_23.rst +++ b/docs/en_US/release_notes_4_23.rst @@ -19,6 +19,7 @@ Housekeeping Bug fixes ********* +| `Issue #3669 `_ - Ensure that proper error should be displayed for the deleted node. | `Issue #3787 `_ - Disabled the Stop process button after clicking it and added a message 'Terminating the process...' to notify the user. | `Issue #5416 `_ - Ensure that the query tool panel gets closed when clicking on the 'Don't Save' button. | `Issue #5465 `_ - Fixed an issue where the Edge browser version is showing wrong and warning message gets displayed. diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py index d798bc14b..5f1078a42 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py @@ -405,7 +405,10 @@ class ForeignServerView(PGChildNodeView): status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) - + if len(res1['rows']) == 0: + return gone( + gettext("The specified foreign server could not be found.") + ) fdw_data = res1['rows'][0] is_valid_options = False diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py index 34200ec04..47ff7e780 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py @@ -411,6 +411,9 @@ class UserMappingView(PGChildNodeView): if not status: return internal_server_error(errormsg=res1) + if len(res1['rows']) == 0: + return gone( + gettext("The specified user mappings could not be found.")) fdw_data = res1['rows'][0] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py index dfecf8fa6..a0e60d049 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/__init__.py @@ -23,6 +23,7 @@ from pgadmin.browser.utils import PGChildNodeView from pgadmin.utils.ajax import make_json_response, internal_server_error, \ make_response as ajax_response, gone from pgadmin.utils.driver import get_driver +from web.pgadmin.utils.exception import ObjectGone class DomainConstraintModule(CollectionNodeModule): @@ -450,6 +451,8 @@ class DomainConstraintView(PGChildNodeView): icon=icon ) ) + except ObjectGone: + raise except Exception as e: return internal_server_error(errormsg=str(e)) @@ -686,6 +689,8 @@ class DomainConstraintView(PGChildNodeView): return True, SQL.strip('\n'), data['name'] else: return True, SQL.strip('\n'), old_data['name'] + except ObjectGone: + raise except Exception as e: return False, internal_server_error(errormsg=str(e)), None @@ -704,6 +709,9 @@ class DomainConstraintView(PGChildNodeView): if not status: return False, internal_server_error(errormsg=res) + if len(res['rows']) == 0: + raise ObjectGone( + gettext("The specified domain could not be found.")) return res['rows'][0]['schema'], res['rows'][0]['domain'] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py index ea4ae81e4..c1ef440dd 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py @@ -458,6 +458,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, status, data = self._fetch_properties(gid, sid, did, scid, foid) if not status: return data + if not data: + return gone( + gettext("The specified foreign table could not be found.")) return ajax_response( response=data, @@ -833,6 +836,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, inherits=True) if not status: return data + if not data: + return gone( + gettext("The specified foreign table could not be found.")) if diff_schema: data['basensp'] = diff_schema @@ -918,6 +924,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, foid, inherits=True) if not status: return old_data + if not old_data: + return gone( + gettext("The specified foreign table could not be found.")) if is_schema_diff: data['is_schema_diff'] = True @@ -1090,7 +1099,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, return False, internal_server_error(errormsg=res) if len(res['rows']) == 0: - return False, False + return True, False data = res['rows'][0] data['is_sys_obj'] = ( @@ -1263,6 +1272,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, status, data = self._fetch_properties(gid, sid, did, scid, foid) if not status: return data + if not data: + return gone( + gettext("The specified foreign table could not be found.")) columns = [] for c in data['columns']: @@ -1298,6 +1310,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, status, data = self._fetch_properties(gid, sid, did, scid, foid) if not status: return data + if not data: + return gone( + gettext("The specified foreign table could not be found.")) columns = [] values = [] @@ -1338,6 +1353,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, status, data = self._fetch_properties(gid, sid, did, scid, foid) if not status: return data + if not data: + return gone( + gettext("The specified foreign table could not be found.")) columns = [] @@ -1382,6 +1400,9 @@ class ForeignTableView(PGChildNodeView, DataTypeReader, status, data = self._fetch_properties(gid, sid, did, scid, foid) if not status: return data + if not data: + return gone( + gettext("The specified foreign table could not be found.")) sql = u"DELETE FROM {0}\n\tWHERE ;".format( self.qtIdent(self.conn, data['basensp'], data['name']) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py index cc449b050..647af85a7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py @@ -1508,6 +1508,8 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare): status, res = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: + return gone(gettext("The specified function could not be found.")) name = self.qtIdent( self.conn, res['rows'][0]['nspname'], diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py index 68b945c56..30513793f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py @@ -593,6 +593,8 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, status, res = self._fetch_properties(did, scid, tid) if not status: return res + if not res['rows']: + return gone(gettext("The specified table could not be found.")) return super(TableView, self).properties( gid, sid, did, scid, tid, res @@ -1151,6 +1153,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: + return gone(gettext("The specified table could not be found.")) + return super(TableView, self).truncate( gid, sid, did, scid, tid, res ) @@ -1370,6 +1375,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, if not status: return res + if len(res['rows']) == 0: + return gone(gettext("The specified table could not be found.")) + data = res['rows'][0] return BaseTableView.get_reverse_engineered_sql( @@ -1399,6 +1407,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: + return gone(gettext("The specified table could not be found.")) + data = res['rows'][0] data = self._formatter(did, scid, tid, data) @@ -1444,6 +1455,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: + return gone(gettext("The specified table could not be found.")) + data = res['rows'][0] data = self._formatter(did, scid, tid, data) @@ -1492,6 +1506,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: + return gone(gettext("The specified table could not be found.")) + data = res['rows'][0] data = self._formatter(did, scid, tid, data) @@ -1542,6 +1559,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: + return gone(gettext("The specified table could not be found.")) + data = res['rows'][0] sql = u"DELETE FROM {0}\n\tWHERE ;".format( @@ -1588,6 +1608,9 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings, data['schema'], data['name'] = \ super(TableView, self).get_schema_and_table_name(tid) + if data['name'] is None: + return gone(gettext("The specified table could not be found.")) + SQL = render_template( "/".join( [self.table_template_path, 'get_table_row_count.sql'] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py index 097c0dd11..f4f3b8108 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py @@ -277,7 +277,6 @@ class ColumnsView(PGChildNodeView, DataTypeReader): status, rset = self.conn.execute_2darray(SQL) if not status: return internal_server_error(errormsg=rset) - if clid is not None: if len(rset['rows']) == 0: return gone( @@ -398,6 +397,8 @@ class ColumnsView(PGChildNodeView, DataTypeReader): # Adding parent into data dict, will be using it while creating sql data['schema'] = self.schema data['table'] = self.table + if len(data['table']) == 0: + return gone(gettext("The specified table could not be found.")) # check type for '[]' in it data['cltype'], data['hasSqrBracket'] = \ diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py index cc3bfd07e..d7420decb 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/__init__.py @@ -491,6 +491,10 @@ class CheckConstraintView(PGChildNodeView): data['schema'] = self.schema data['table'] = self.table + # Checking whether the table is deleted via query tool + if len(data['table']) == 0: + return gone(_("The specified table could not be found.")) + try: if 'name' not in data or data['name'] == "": SQL = "BEGIN;" diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py index da520aa9e..c028bc978 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py @@ -588,6 +588,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare): # Adding parent into data dict, will be using it while creating sql data['schema'] = self.schema data['table'] = self.table + if len(data['table']) == 0: + return gone(gettext("The specified table could not be found.")) try: # Start transaction. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py index dbf57ccf4..dfc84b00f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py @@ -544,6 +544,8 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare): # Adding parent into data dict, will be using it while creating sql data['schema'] = self.schema data['table'] = self.table + if len(data['table']) == 0: + return gone(gettext("The specified object could not be found.")) try: SQL = render_template("/".join([self.template_path, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py index 6a442bfd6..93570d166 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py @@ -19,7 +19,7 @@ from flask_babelex import gettext from pgadmin.browser.server_groups.servers.databases.schemas\ .tables.base_partition_table import BasePartitionTable from pgadmin.utils.ajax import make_json_response, internal_server_error, \ - make_response as ajax_response + gone, make_response as ajax_response from pgadmin.browser.server_groups.servers.databases.schemas.utils \ import DataTypeReader, parse_rule_definition from pgadmin.browser.server_groups.servers.utils import parse_priv_from_db, \ @@ -657,6 +657,13 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): scid: Schema ID tid: Table ID """ + # checking the table existence using the function of the same class + schema_name, table_name = self.get_schema_and_table_name(tid) + + if table_name is None: + return gone(gettext("The specified table could not be found.")) + + # table exist try: SQL = render_template("/".join([self.table_template_path, 'reset_stats.sql']), @@ -1061,6 +1068,13 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): parent_id: parent table id if current table is partition of parent table else none """ + # checking the table existence using the function of the same class + schema_name, table_name = self.get_schema_and_table_name(tid) + + if table_name is None: + return gone(gettext("The specified table could not be found.")) + + # table exists try: SQL, name = self.get_sql(did, scid, tid, data, res) @@ -1478,6 +1492,8 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): 'get_schema_oid.sql']), tid=tid)) if not status: return internal_server_error(errormsg=scid) + if scid is None: + return None, None # Fetch schema name status, schema_name = self.conn.execute_scalar( diff --git a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js index af2de4aad..8a130df8a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js +++ b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.js @@ -574,6 +574,9 @@ define('pgadmin.node.database', [ return onSuccess(res, obj, data, tree, item, wasConnected); } }).fail(function(xhr, status, error) { + if (xhr.status === 410) { + error = gettext('Error: Object not found - %s.', error); + } return onFailure( xhr, status, error, obj, data, tree, item, wasConnected ); diff --git a/web/pgadmin/browser/server_groups/servers/roles/__init__.py b/web/pgadmin/browser/server_groups/servers/roles/__init__.py index a98c883ce..389da72f3 100644 --- a/web/pgadmin/browser/server_groups/servers/roles/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/roles/__init__.py @@ -763,7 +763,7 @@ rolmembership:{ ) ) - if res is None: + if res is None or (len(res) == 0): return gone( _("Could not generate reversed engineered query for the role.") ) diff --git a/web/pgadmin/browser/static/js/error.js b/web/pgadmin/browser/static/js/error.js index 07bfe43ac..911234193 100644 --- a/web/pgadmin/browser/static/js/error.js +++ b/web/pgadmin/browser/static/js/error.js @@ -13,7 +13,7 @@ define( pgAdmin.Browser = pgAdmin.Browser || {}; _.extend(pgAdmin.Browser, { - report_error: function(title, message, info) { + report_error: function(title, message, info, callback) { title = _.escape(title); message = _.escape(message); info = _.escape(info); @@ -49,7 +49,14 @@ define( alertify.alert( title, text - ).set('closable', true); + ) + .set({'closable': true, + 'onok': function() { + if(callback) { + callback(); + } + }, + }); }, }); diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index f3a927efa..7c5db61f2 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -815,7 +815,7 @@ define('pgadmin.browser.node', [ if (jqx.status == 417 || jqx.status == 410 || jqx.status == 500) { try { var data = JSON.parse(jqx.responseText); - msg = data.errormsg; + msg = data.info || data.errormsg; } catch (e) { console.warn(e.stack || e); } diff --git a/web/pgadmin/browser/static/js/toolbar.js b/web/pgadmin/browser/static/js/toolbar.js index 6eb1f39f4..9b809d4ce 100644 --- a/web/pgadmin/browser/static/js/toolbar.js +++ b/web/pgadmin/browser/static/js/toolbar.js @@ -1,3 +1,4 @@ + ///////////////////////////////////////////////////////////// // // pgAdmin 4 - PostgreSQL Tools diff --git a/web/pgadmin/static/js/alertify.pgadmin.defaults.js b/web/pgadmin/static/js/alertify.pgadmin.defaults.js index daa60f696..aea2ad0dd 100644 --- a/web/pgadmin/static/js/alertify.pgadmin.defaults.js +++ b/web/pgadmin/static/js/alertify.pgadmin.defaults.js @@ -158,41 +158,46 @@ define([ alertify.pgRespErrorNotify = (xhr, error, prefixMsg='') => { var contentType = xhr.getResponseHeader('Content-Type'); - try { - if (xhr.status === 0) { - error = gettext('Connection to the server has been lost.'); - } else { - if(contentType){ - if(contentType.indexOf('application/json') >= 0) { - var resp = JSON.parse(xhr.responseText); - error = _.escape(resp.result) || _.escape(resp.errormsg) || gettext('Unknown error'); + if (xhr.status === 410) { + const pgBrowser = window.pgAdmin.Browser; + pgBrowser.report_error(gettext('Error: Object not found - %s.', xhr.statusText), xhr.responseJSON.errormsg); + } else { + try { + if (xhr.status === 0) { + error = gettext('Connection to the server has been lost.'); + } else { + if(contentType){ + if(contentType.indexOf('application/json') >= 0) { + var resp = JSON.parse(xhr.responseText); + error = _.escape(resp.result) || _.escape(resp.errormsg) || gettext('Unknown error'); + } + } + if (contentType.indexOf('text/html') >= 0) { + var alertMessage = '\ +
\ +
\ +
\ + \ +
\ +
'; + + alertify.notify( + alertMessage, 'error', 0, () => { + alertify.pgIframeDialog() + .show() + .set({frameless: false}) + .set('pg_msg', xhr.responseText); + } + ); + return; } } - if (contentType.indexOf('text/html') >= 0) { - var alertMessage = '\ -
\ -
\ -
\ - \ -
\ -
'; - - alertify.notify( - alertMessage, 'error', 0, () => { - alertify.pgIframeDialog() - .show() - .set({frameless: false}) - .set('pg_msg', xhr.responseText); - } - ); - return; - } } + catch(e){ + error = e.message; + } + alertify.error(prefixMsg +' '+error); } - catch(e){ - error = e.message; - } - alertify.error(prefixMsg +' '+error); }; var alertifyDialogResized = function(stop) { diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py index aa300c198..b89d2b423 100644 --- a/web/pgadmin/tools/datagrid/__init__.py +++ b/web/pgadmin/tools/datagrid/__init__.py @@ -31,6 +31,7 @@ from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost from pgadmin.utils.preferences import Preferences from pgadmin.settings import get_setting from pgadmin.browser.utils import underscore_unescape +from web.pgadmin.utils.exception import ObjectGone MODULE_NAME = 'datagrid' @@ -180,6 +181,8 @@ def initialize_datagrid(trans_id, cmd_type, obj_type, sgid, sid, did, obj_id): did=did, obj_id=obj_id, cmd_type=cmd_type, sql_filter=filter_sql ) + except ObjectGone: + raise except Exception as e: app.logger.error(e) return internal_server_error(errormsg=str(e)) @@ -434,6 +437,8 @@ def validate_filter(sid, did, obj_id): # Call validate_filter method to validate the SQL. status, res = sql_filter_obj.validate_filter(filter_sql) + except ObjectGone: + raise except Exception as e: app.logger.error(e) return internal_server_error(errormsg=str(e)) diff --git a/web/pgadmin/tools/datagrid/static/js/show_data.js b/web/pgadmin/tools/datagrid/static/js/show_data.js index d2700cfbf..b6973133b 100644 --- a/web/pgadmin/tools/datagrid/static/js/show_data.js +++ b/web/pgadmin/tools/datagrid/static/js/show_data.js @@ -241,10 +241,16 @@ function initFilterDialog(alertify, pgBrowser) { } }) .fail(function(e) { - alertify.alert( - gettext('Validation Error'), - e - ); + if (e.status === 410){ + pgBrowser.report_error(gettext('Error filtering rows - %s.', e.statusText), e.responseJSON.errormsg); + + } else { + alertify.alert( + gettext('Validation Error'), + e + ); + } + }); } else if(closeEvent.index == 0) { /* help Button */ diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index 6c4e39c56..cd1467355 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -24,7 +24,7 @@ from pgadmin.utils import PgAdminModule, \ ACCESSKEY_FIELDS as accesskey_fields from pgadmin.utils.ajax import bad_request from pgadmin.utils.ajax import make_json_response, \ - internal_server_error + internal_server_error, gone from pgadmin.utils.driver import get_driver from pgadmin.settings import get_setting @@ -391,6 +391,9 @@ def init_function(node_type, sid, did, scid, fid, trid=None): "Error retrieving function information from database") return internal_server_error(errormsg=r_set) + if len(r_set['rows']) == 0: + return gone( + gettext("The specified %s could not be found." % node_type)) ret_status = status # Check that the function is actually debuggable... diff --git a/web/pgadmin/tools/sqleditor/command.py b/web/pgadmin/tools/sqleditor/command.py index 4df1ef901..51d68622a 100644 --- a/web/pgadmin/tools/sqleditor/command.py +++ b/web/pgadmin/tools/sqleditor/command.py @@ -21,6 +21,7 @@ from pgadmin.tools.sqleditor.utils.is_query_resultset_updatable \ from pgadmin.tools.sqleditor.utils.save_changed_data import save_changed_data from pgadmin.tools.sqleditor.utils.get_column_types import get_columns_types from pgadmin.utils.preferences import Preferences +from web.pgadmin.utils.exception import ObjectGone from config import PG_DEFAULT_DRIVER @@ -187,6 +188,9 @@ class SQLFilter(object): status, result = conn.execute_dict(query) if not status: raise Exception(result) + if len(result['rows']) == 0: + raise ObjectGone( + gettext("The specified object could not be found.")) self.nsp_name = result['rows'][0]['nspname'] self.object_name = result['rows'][0]['relname'] diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index fe4b6b5e0..d883f250f 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -2107,9 +2107,18 @@ define('tools.querytool', [ 'pgadmin:query_tool:connected:' + self.transId, res.data ); }).fail((xhr, status, error)=>{ - pgBrowser.Events.trigger( - 'pgadmin:query_tool:connected_fail:' + self.transId, xhr, error - ); + if (xhr.status === 410) { + //checking for Query tool in new window. + if(self.preferences.new_browser_tab) { + pgBrowser.report_error(gettext('Error fetching rows - %s.', xhr.statusText), xhr.responseJSON.errormsg, undefined, window.close); + } else { + pgBrowser.report_error(gettext('Error fetching rows - %s.', xhr.statusText), xhr.responseJSON.errormsg, undefined, self.close.bind(self)); + } + } else { + pgBrowser.Events.trigger( + 'pgadmin:query_tool:connected_fail:' + self.transId, xhr, error + ); + } }); }, @@ -2316,10 +2325,14 @@ define('tools.querytool', [ msg = httpErrorHandler.handleQueryToolAjaxError( pgAdmin, self, jqx, null, [], false ); - if (msg) - pgBrowser.report_error( - gettext('Error fetching SQL for script: %s.', msg) - ); + if (msg) { + if(self.preferences.new_browser_tab) { + pgBrowser.report_error(gettext('Error fetching SQL for script - %s.', jqx.statusText), jqx.responseJSON.errormsg, undefined, window.close); + } else { + pgBrowser.report_error(gettext('Error fetching SQL for script - %s.', jqx.statusText), jqx.responseJSON.errormsg, undefined, self.close.bind(self)); + } + } + }); } } diff --git a/web/pgadmin/utils/driver/psycopg2/server_manager.py b/web/pgadmin/utils/driver/psycopg2/server_manager.py index 6e242403d..4e1395bbb 100644 --- a/web/pgadmin/utils/driver/psycopg2/server_manager.py +++ b/web/pgadmin/utils/driver/psycopg2/server_manager.py @@ -25,6 +25,7 @@ from pgadmin.model import Server, User from pgadmin.utils.exception import ConnectionLost, SSHTunnelConnectionLost,\ CryptKeyMissing from pgadmin.utils.master_password import get_crypt_key +from pgadmin.utils.exception import ObjectGone if config.SUPPORT_SSH_TUNNEL: from sshtunnel import SSHTunnelForwarder, BaseSSHTunnelForwarderError @@ -209,7 +210,7 @@ WHERE db.oid = {0}""".format(did)) database = self.db_info[did]['datname'] if did not in self.db_info: - raise Exception(gettext( + raise ObjectGone(gettext( "Could not find the specified database." ))