mapledan opened a new pull request, #30063:
URL: https://github.com/apache/superset/pull/30063
### SUMMARY
This pull request addresses an issue in the sql_lab async task where
arguments are retrieved incorrectly when a backoff occurs. The error caused the
task to fail or produce unintended results due to incorrect handling of
arguments during the backoff process.
```
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line
736, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.SerializationFailure: could not serialize access due to
concurrent update
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/superset/sql_lab.py", line 181, in get_sql_results
return execute_sql_statements(
File "/app/superset/sql_lab.py", line 439, in execute_sql_statements
db.session.commit()
File "<string>", line 2, in commit
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 1454, in commit
self._transaction.commit(_to_root=self.future)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 832, in commit
self._prepare_impl()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 811, in _prepare_impl
self.session.flush()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 3449, in flush
self._flush(objects)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 3588, in _flush
with util.safe_reraise():
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line
70, in __exit__
compat.raise_(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py",
line 211, in raise_
raise exception
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 3549, in _flush
flush_context.execute()
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line
456, in execute
rec.execute(self)
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line
630, in execute
util.preloaded.orm_persistence.save_obj(
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line
237, in save_obj
_emit_update_statements(
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line
1001, in _emit_update_statements
c = connection._execute_20(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py",
line 1710, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py",
line 334, in _execute_on_connection
return connection._execute_clauseelement(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py",
line 1577, in _execute_clauseelement
ret = self._execute_context(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py",
line 1953, in _execute_context
self._handle_dbapi_exception(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py",
line 2134, in _handle_dbapi_exception
util.raise_(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py",
line 211, in raise_
raise exception
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line
736, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (psycopg2.errors.SerializationFailure)
could not serialize access due to concurrent update
[SQL: UPDATE query SET status=%(status)s,
start_running_time=%(start_running_time)s, changed_on=%(changed_on)s WHERE
query.id = %(query_id)s]
[parameters: {'status': <QueryStatus.RUNNING: 'running'>,
'start_running_time': 1725000230086.534, 'changed_on': datetime.datetime(2024,
8, 30, 6, 43, 50, 87413), 'query_id': 77096}]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/superset/sql_lab.py", line 157, in get_query
return db.session.query(Query).filter_by(id=query_id).one()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/query.py",
line 2870, in one
return self._iter().one()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/query.py",
line 2916, in _iter
result = self.session.execute(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 1716, in execute
conn = self._connection_for_bind(bind)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 1555, in _connection_for_bind
return self._transaction._connection_for_bind(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 724, in _connection_for_bind
self._assert_active()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py",
line 604, in _assert_active
raise sa_exc.PendingRollbackError(
sqlalchemy.exc.PendingRollbackError: This Session's transaction has been
rolled back due to a previous exception during flush. To begin a new
transaction with this Session, first issue Session.rollback(). Original
exception was: (psycopg2.errors.SerializationFailure) could not serialize
access due to concurrent update
[SQL: UPDATE query SET status=%(status)s,
start_running_time=%(start_running_time)s, changed_on=%(changed_on)s WHERE
query.id = %(query_id)s]
[parameters: {'status': <QueryStatus.RUNNING: 'running'>,
'start_running_time': 1725000230086.534, 'changed_on': datetime.datetime(2024,
8, 30, 6, 43, 50, 87413), 'query_id': 77096}]
(Background on this error at: https://sqlalche.me/e/14/e3q8) (Background on
this error at: https://sqlalche.me/e/14/7s2a)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/backoff/_sync.py", line 105,
in retry
ret = target(*args, **kwargs)
File "/app/superset/sql_lab.py", line 159, in get_query
raise SqlLabException("Failed at getting query") from ex
superset.sql_lab.SqlLabException: Failed at getting query
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/celery/app/trace.py", line
453, in trace_task
R = retval = fun(*args, **kwargs)
File "/app/superset/initialization/__init__.py", line 111, in __call__
return task_base.__call__(self, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/celery/app/trace.py", line
736, in __protected_call__
return self.run(*args, **kwargs)
File "/app/superset/sql_lab.py", line 193, in get_sql_results
query = get_query(query_id)
File "/usr/local/lib/python3.10/site-packages/backoff/_sync.py", line 124,
in retry
_call_handlers(on_backoff, **details, wait=seconds,
File "/usr/local/lib/python3.10/site-packages/backoff/_sync.py", line 20,
in _call_handlers
hdlr(details)
File "/app/superset/sql_lab.py", line 132, in get_query_backoff_handler
query_id = details["kwargs"]["query_id"]
KeyError: 'query_id'
```

### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
### TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]