Add numerous missing checks to ensure objects really exist when we think they do. Fixes #2427

This commit is contained in:
Murtuza Zabuawala
2017-05-25 16:28:04 -04:00
committed by Dave Page
parent 04ce72a6ae
commit e9da157cc7
36 changed files with 683 additions and 136 deletions
@@ -21,8 +21,11 @@ from pgadmin.utils.ajax import make_json_response, \
make_response as ajax_response, internal_server_error, gone
from pgadmin.utils.ajax import precondition_required
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.utils import IS_PY2
# If we are in Python3
if not IS_PY2:
unicode = str
class TablespaceModule(CollectionNodeModule):
@@ -350,6 +353,10 @@ class TablespaceView(PGChildNodeView):
try:
SQL, name = self.get_sql(gid, sid, data, tsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return SQL
SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL)
if not status:
@@ -433,6 +440,10 @@ class TablespaceView(PGChildNodeView):
data[k] = v
sql, name = self.get_sql(gid, sid, data, tsid)
# Most probably this is due to error
if not isinstance(sql, (str, unicode)):
return sql
sql = sql.strip('\n').strip(' ')
if sql == '':
sql = "--modified SQL"
@@ -458,6 +469,11 @@ class TablespaceView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the tablespace on the server.")
)
# Making copy of output for further processing
old_data = dict(res['rows'][0])
old_data = self._formatter(old_data, tsid)
@@ -512,6 +528,10 @@ class TablespaceView(PGChildNodeView):
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
_("Could not find the tablespace on the server.")
)
# Making copy of output for future use
old_data = dict(res['rows'][0])