Ensure that proper error should be displayed for the deleted node. Fixes #3669

pull/33/head
Satish V 2020-06-03 11:26:26 +05:30 committed by Akshay Joshi
parent 3d0319dba7
commit d22e276586
24 changed files with 186 additions and 52 deletions

View File

@ -19,6 +19,7 @@ Housekeeping
Bug fixes
*********
| `Issue #3669 <https://redmine.postgresql.org/issues/3669>`_ - Ensure that proper error should be displayed for the deleted node.
| `Issue #3787 <https://redmine.postgresql.org/issues/3787>`_ - Disabled the Stop process button after clicking it and added a message 'Terminating the process...' to notify the user.
| `Issue #5416 <https://redmine.postgresql.org/issues/5416>`_ - Ensure that the query tool panel gets closed when clicking on the 'Don't Save' button.
| `Issue #5465 <https://redmine.postgresql.org/issues/5465>`_ - Fixed an issue where the Edge browser version is showing wrong and warning message gets displayed.

View File

@ -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

View File

@ -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]

View File

@ -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']

View File

@ -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 <condition>;".format(
self.qtIdent(self.conn, data['basensp'], data['name'])

View File

@ -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'],

View File

@ -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 <condition>;".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']

View File

@ -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'] = \

View File

@ -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;"

View File

@ -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.

View File

@ -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,

View File

@ -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(

View File

@ -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
);

View File

@ -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.")
)

View File

@ -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();
}
},
});
},
});

View File

@ -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);
}

View File

@ -1,3 +1,4 @@
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools

View File

@ -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 = '\
<div class="media text-danger text-14">\
<div class="media-body media-middle">\
<div class="alert-text" role="alert">' + gettext('INTERNAL SERVER ERROR') + '</div><br/>\
<div class="alert-text" role="alert">' + gettext('Click for details.') + '</div>\
</div>\
</div>';
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 = '\
<div class="media text-danger text-14">\
<div class="media-body media-middle">\
<div class="alert-text" role="alert">' + gettext('INTERNAL SERVER ERROR') + '</div><br/>\
<div class="alert-text" role="alert">' + gettext('Click for details.') + '</div>\
</div>\
</div>';
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) {

View File

@ -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))

View File

@ -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 */

View File

@ -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...

View File

@ -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']

View File

@ -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));
}
}
});
}
}

View File

@ -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."
))