bikash-barnwal commented on issue #40903:
URL: https://github.com/apache/superset/issues/40903#issuecomment-5298274596
This was fixed on master by #41642 (`bdc610c572`, 2026-07-02) — after the
last report here (2026-06-19), which is why the published image you tested
still showed it.
The comment above correctly identified the mechanism, and the fix takes
exactly that route: when a database has prequeries, the engine is no longer
taken from the shared cache, so the per-call `connect` listener is never added
to or removed from an engine another thread is using. From
`superset/models/core.py`:
```python
# Prequeries attach a per-call ``connect`` listener below
# (and remove it on exit). SQLAlchemy's listener collection
# is an unlocked deque, so mutating it on an engine shared
# via ``_ENGINE_CACHE`` races with concurrent connection
# checkouts iterating the same deque ("RuntimeError: deque
# mutated during iteration", surfacing as 500s). Request a
# private, uncached engine whenever prequeries are present
# so the listener add/remove never touches a shared object.
engine = self._get_sqla_engine(
...
cacheable=not prequeries,
)
```
The private engine is also disposed in the `finally`, so its pool is
released immediately rather than lingering until GC.
Worth confirming on current master or a nightly before closing — the failure
was intermittent and load-dependent, so absence over a short run isn't proof.
But no further code change looks needed for the race described here.
--
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]