GitHub user dosubot[bot] added a comment to the discussion: Upgrade to Superset
Version 5 to 6 (Issues Faced)
<!-- Answer -->
The ImportError happens because Superset 6.x (with Flask-AppBuilder 5.x) no
longer supports importing `SQLA` directly from `flask_appbuilder`. Instead,
Superset now exposes a singleton SQLAlchemy instance via
`superset.extensions.db`, and all session management should use `db.session`
from there. This keeps your code aligned with Superset’s app lifecycle and
avoids session/context issues.
To fix your code, replace:
```python
from flask_appbuilder import SQLA
from sqlalchemy.orm import Session
class DashboardModelView1(BaseFormView):
session: Session = SQLA().session
```
with:
```python
from superset.extensions import db
from sqlalchemy.orm import Session
class DashboardModelView1(BaseFormView):
session: Session = db.session
```
You can then use `self.session.execute(...)` and `self.session.commit()` as
before. This pattern matches how Superset internally manages sessions and is
the recommended approach for custom extensions or config overrides in 6.x
[source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/extensions/__init__.py#L23-L126).
Also, make sure your dependencies are compatible: Flask-AppBuilder 5.x requires
Flask-SQLAlchemy 3.x. If you see related errors, update your dependency to
`flask-sqlalchemy>=3.0.0,<4.0`.
No official migration guide exists for this change, but following the above
pattern will resolve the ImportError and keep your session management
compatible with Superset 6.x
[source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/initialization/__init__.py#L38-L621).
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/6d2efb45-138c-411e-9015-3c15e4a659cf?feedback_type=other)</sup>
[](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github) [](https://cursor.com/link/prompt?text=The%20ImportError%20happens%20because%20Superset%206.x%20%28with%20Flask-AppBuilder%205.x%29%20no%20longer%20supports%20importing%20%60SQLA%60%20directly%20from%20%60flask_appbuilder%60.%20Instead%2C%20Superset%20now%20exposes%20a%20singleton%20SQLAlchemy%20instance%20via%20%60superset.extensions.db%60%2C%20and%20all%20session%20management%20should%20use%20%60db.session%60%20from%20there.%20This%20keeps%20your%20code%20aligned%20with%20Superset%E2%80%99s%20app%20lifecycle%20and%20avoids%20session/context%20issues.%0A%0ATo%20fix%20your%20code%2C%20replace%3A%0A%0A%60%60%60python%0Afrom%20flask_appbuilder%20import%20SQLA%0Afrom%20sqlalchemy.orm%20import%20Session%0A%0Aclass%20DashboardModelView1%28BaseFormView%29%3A%0A%20%20%20%20session%3A%20Session%20
%3D%20SQLA%28%29.session%0A%60%60%60%0A%0Awith%3A%0A%0A%60%60%60python%0Afrom%20superset.extensions%20import%20db%0Afrom%20sqlalchemy.orm%20import%20Session%0A%0Aclass%20DashboardModelView1%28BaseFormView%29%3A%0A%20%20%20%20session%3A%20Session%20%3D%20db.session%0A%60%60%60%0A%0AYou%20can%20then%20use%20%60self.session.execute%28...%29%60%20and%20%60self.session.commit%28%29%60%20as%20before.%20This%20pattern%20matches%20how%20Superset%20internally%20manages%20sessions%20and%20is%20the%20recommended%20approach%20for%20custom%20extensions%20or%20config%20overrides%20in%206.x%20%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/extensions/__init__.py%23L23-L126%29.%0A%0AAlso%2C%20make%20sure%20your%20dependencies%20are%20compatible%3A%20Flask-AppBuilder%205.x%20requires%20Flask-SQLAlchemy%203.x.%20If%20you%20see%20related%20errors%2C%20update%20your%20dependency%20to%20%60flask-sqlalchemy%3E%3D3.0.0%2C%3C4.0%60.%0A%0ANo%20offic
ial%20migration%20guide%20exists%20for%20this%20change%2C%20but%20following%20the%20above%20pattern%20will%20resolve%20the%20ImportError%20and%20keep%20your%20session%20management%20compatible%20with%20Superset%206.x%20%5Bsource%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/initialization/__init__.py%23L38-L621%29.) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/36869)
GitHub link:
https://github.com/apache/superset/discussions/36869#discussioncomment-15373635
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]