Ensure we capture notices raised by queries. Fixes #3027

pull/7/head
Murtuza Zabuawala 2018-02-02 15:23:33 +01:00 committed by Dave Page
parent 4d69764869
commit 25647c16ba
2 changed files with 23 additions and 6 deletions

View File

@ -760,6 +760,14 @@ def poll(trans_id):
status, result = conn.poll( status, result = conn.poll(
formatted_exception_msg=True, no_result=True) formatted_exception_msg=True, no_result=True)
if not status: 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) return internal_server_error(result)
elif status == ASYNC_OK: elif status == ASYNC_OK:
status = 'Success' status = 'Success'
@ -800,10 +808,11 @@ def poll(trans_id):
conn.manager.version conn.manager.version
) )
SQL = render_template("/".join([template_path, SQL = render_template(
'nodes.sql']), "/".join([template_path,'nodes.sql']),
tid=command_obj.obj_id, tid=command_obj.obj_id,
has_oids=True) has_oids=True
)
# rows with attribute not_null # rows with attribute not_null
colst, rset = conn.execute_2darray(SQL) colst, rset = conn.execute_2darray(SQL)
if not colst: if not colst:
@ -973,7 +982,8 @@ def fetch(trans_id, fetch_all=None):
return make_json_response( return make_json_response(
data={ data={
'status': status, 'result': result, 'status': status,
'result': result,
'has_more_rows': has_more_rows, 'has_more_rows': has_more_rows,
'rows_fetched_from': rows_fetched_from, 'rows_fetched_from': rows_fetched_from,
'rows_fetched_to': rows_fetched_to 'rows_fetched_to': rows_fetched_to

View File

@ -1333,6 +1333,7 @@ Failed to reset the connection to the server due to following error:
) )
) )
is_error = False
try: try:
status = self._wait_timeout(self.conn) status = self._wait_timeout(self.conn)
except psycopg2.Error as pe: 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:] self.conn_id[5:]
) )
errmsg = self._formatted_exception_msg(pe, formatted_exception_msg) 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: if self.conn.notices and self.__notices is not None:
while self.conn.notices: while self.conn.notices:
self.__notices.append(self.conn.notices.pop(0)[:]) 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 result = None
self.row_count = 0 self.row_count = 0
self.column_info = None self.column_info = None