From b9736cbd74c723ce914fa3beaafe03fd284daf45 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Wed, 21 Jun 2017 16:59:43 +0100 Subject: [PATCH] Handle missing/dropped synonyms gracefully. Fixes #2503 --- .../databases/schemas/synonyms/__init__.py | 60 ++++++++----------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py index 50fd219ff..e49ab4361 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/synonyms/__init__.py @@ -334,18 +334,28 @@ class SynonymView(PGChildNodeView): except ValueError: data[k] = v - sql = render_template("/".join([self.template_path, - 'get_objects.sql']), - trgTyp=data['trgTyp'], - trgSchema=data['trgSchema']) - status, rset = self.conn.execute_dict(sql) + is_valid_request = True + if 'trgTyp' not in data or data['trgTyp'] is None or \ + data['trgTyp'].strip() == '': + is_valid_request = False - if not status: - return internal_server_error(errormsg=rset) + if 'trgSchema' not in data or data['trgSchema'] is None or \ + data['trgSchema'].strip() == '': + is_valid_request = False - for row in rset['rows']: - res.append({'label': row['name'], - 'value': row['name']}) + if is_valid_request: + sql = render_template("/".join([self.template_path, + 'get_objects.sql']), + trgTyp=data['trgTyp'], + trgSchema=data['trgSchema']) + status, rset = self.conn.execute_dict(sql) + + if not status: + return internal_server_error(errormsg=rset) + + for row in rset['rows']: + res.append({'label': row['name'], + 'value': row['name']}) return make_json_response( data=res, @@ -384,14 +394,8 @@ class SynonymView(PGChildNodeView): status=200 ) else: - return make_json_response( - success=410, - errormsg=gettext( - 'Error: Object not found.' - ), - info=gettext( - 'The specified synonym could not be found.\n' - ) + return gone( + gettext('The specified synonym could not be found.') ) except Exception as e: @@ -483,14 +487,8 @@ class SynonymView(PGChildNodeView): if len(res['rows']) > 0: data = res['rows'][0] else: - return make_json_response( - success=0, - errormsg=gettext( - 'Error: Object not found.' - ), - info=gettext( - 'The specified synonym could not be found.\n' - ) + return gone( + gettext('The specified synonym could not be found.') ) SQL = render_template("/".join([self.template_path, @@ -646,14 +644,8 @@ class SynonymView(PGChildNodeView): if len(res['rows']) > 0: data = res['rows'][0] else: - return make_json_response( - success=0, - errormsg=gettext( - 'Error: Object not found.' - ), - info=gettext( - 'The specified synonym could not be found.\n' - ) + return gone( + gettext('The specified synonym could not be found.') ) SQL = render_template("/".join([self.template_path,