Skip to content

Commit

Permalink
Fix rollback and commit button activation on execute button click. pg…
Browse files Browse the repository at this point in the history
  • Loading branch information
anilsahoo20 committed Mar 27, 2024
1 parent b742487 commit b857477
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
24 changes: 13 additions & 11 deletions web/pgadmin/tools/sqleditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,14 @@ def poll(trans_id):
is_thread_alive = True
break

# if transaction object is instance of QueryToolCommand
# and transaction aborted for some reason then issue a
# rollback to cleanup
if isinstance(trans_obj, QueryToolCommand):
trans_status = conn.transaction_status()
if trans_status == TX_STATUS_INERROR and trans_obj.auto_rollback:
conn.execute_void("ROLLBACK;")

if is_thread_alive:
status = 'Busy'
messages = conn.messages()
Expand All @@ -973,25 +981,19 @@ def poll(trans_id):
gettext('******* Error *******'),
result
)

transaction_status = conn.transaction_status() if conn else 0
query_len_data = {
'transaction_status': transaction_status,
'explain_query_length':
get_explain_query_length(
conn._Connection__async_cursor._query)
get_explain_query_length(
conn._Connection__async_cursor._query)
}
return internal_server_error(result, query_len_data)
elif status == ASYNC_OK:
status = 'Success'
rows_affected = conn.rows_affected()

# if transaction object is instance of QueryToolCommand
# and transaction aborted for some reason then issue a
# rollback to cleanup
if isinstance(trans_obj, QueryToolCommand):
trans_status = conn.transaction_status()
if trans_status == TX_STATUS_INERROR and \
trans_obj.auto_rollback:
conn.execute_void("ROLLBACK;")

st, result = conn.async_fetchmany_2darray(on_demand_record_count)

# There may be additional messages even if result is present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ export class ResultSetUtils {
}
try {
let {data: httpMessageData} = await this.postExecutionApi(query, explainObject, flags.isQueryTool, flags.reconnect);
this.eventBus.fireEvent(QUERY_TOOL_EVENTS.SET_CONNECTION_STATUS, httpMessageData.data.transaction_status);

if (ResultSetUtils.isSqlCorrect(httpMessageData)) {
this.setStartData(httpMessageData.data);
Expand Down Expand Up @@ -281,7 +280,7 @@ export class ResultSetUtils {
handlePollError(error, explainObject, flags) {
this.eventBus.fireEvent(QUERY_TOOL_EVENTS.EXECUTION_END);
this.eventBus.fireEvent(QUERY_TOOL_EVENTS.FOCUS_PANEL, PANELS.MESSAGES);
this.eventBus.fireEvent(QUERY_TOOL_EVENTS.SET_CONNECTION_STATUS, CONNECTION_STATUS.TRANSACTION_STATUS_INERROR);
this.eventBus.fireEvent(QUERY_TOOL_EVENTS.SET_CONNECTION_STATUS, error.response.data.data.transaction_status);
if (!flags.external) {
this.eventBus.fireEvent(QUERY_TOOL_EVENTS.HIGHLIGHT_ERROR, parseApiError(error, true));
}
Expand Down
1 change: 0 additions & 1 deletion web/pgadmin/tools/sqleditor/utils/start_running_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def execute(self, sql, trans_id, http_session, connect=False):
'status': status, 'result': result,
'can_edit': can_edit, 'can_filter': can_filter,
'notifies': notifies,
'transaction_status': trans_status,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ class StartRunningQueryTest(BaseTestGenerator):
'not found.',
can_edit=False,
can_filter=False,
notifies=None,
transaction_status=None
notifies=None
)
),
expect_internal_server_error_called_with=None,
Expand Down

0 comments on commit b857477

Please sign in to comment.