rusackas commented on code in PR #42803:
URL: https://github.com/apache/superset/pull/42803#discussion_r3733097963


##########
superset/extensions/__init__.py:
##########
@@ -154,7 +154,19 @@ def init_app(self, app: Flask) -> None:
 cache_manager = CacheManager()
 celery_app = celery.Celery()
 csrf = CSRFProtect()
-db = get_sqla_class()()
+
+# Flask-SQLAlchemy 3.x scopes db.session by the identity of the current Flask
+# app-context object (id(app_ctx)) rather than by thread/greenlet identity like
+# 2.x did. Superset's codebase (and its test fixtures) widely assumes a single
+# shared session per thread across nested `app.app_context()` blocks, often
+# relying on that implicit sharing instead of an explicit commit. Restoring the
+# 2.x scopefunc here keeps that assumption valid under FSA 3.x.
+try:
+    from greenlet import getcurrent as _session_scopefunc
+except ImportError:
+    from threading import get_ident as _session_scopefunc
+
+db = get_sqla_class()(session_options={"scopefunc": _session_scopefunc})

Review Comment:
   The premature-removal risk is real for the general FSA3 pattern, but it only 
bites on nested `app.app_context()` calls that share the thread scopefunc key. 
I audited the call sites this branch touches (`tasks/context.py`, the celery 
task base in `initialization/__init__.py`) and each already guards with 
`has_app_context()` before pushing a new context, so they never nest under the 
current code. Leaving the scopefunc override as-is rather than adding 
refcounted teardown on top of it.



-- 
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]

Reply via email to