codeant-ai-for-open-source[bot] commented on code in PR #42803:
URL: https://github.com/apache/superset/pull/42803#discussion_r3733099947
##########
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:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag the greenlet/thread session scope override for nested
application-context teardown when the affected call sites guard context
creation with has_app_context() and do not nest contexts.
**Applied to:**
- `superset/extensions/__init__.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]