Repository navigation
Conversation
|
Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment
|
|
Any idea on estimated timeline for this compatibility with SQLAlchemy 2.0? No further releases expected for SQLAlchemy 1.4, it is EOL according to Mike Bayer - sqlalchemy/sqlalchemy#13009 |
|
@dpgaspar do you still intend to get this through? Needs a big ol' rebase, but seems like important work :D |
|
@dpgaspar this hit my stale draft radar again... not sure if you're picking this back up, but I might close it out next time it hits 90+ days again to thin the herd. |
|
Yeah, you're right... the effort is moving forward, this PR doesn't seem to be. Closing for now, but happy to reopen, or @dpgaspar can do the same if he wants to :D |
Summary
This PR upgrades Apache Superset to Flask 3.x and SQLAlchemy 2.x while maintaining backward compatibility with SQLAlchemy 1.4.54. This is a critical upgrade to keep Superset current with the Flask/SQLAlchemy ecosystem and enable future feature development.
Background: The Flask 3.x Dependency Challenge
Upgrading to Flask 3.x presents a unique challenge due to interdependencies between Flask, Flask-SQLAlchemy, and SQLAlchemy versions:
The Dependency Matrix Problem:
This creates two mutually exclusive dependency chains:
This PR implements the complete upgrade to Flask 3.x + Flask-SQLAlchemy 3.x + SQLAlchemy 2.x, ensuring all components work together properly.
SQLAlchemy 2.x Migration Patterns
This PR implements all necessary SQLAlchemy 2.x migration patterns while maintaining backward compatibility with 1.4.54:
1. Engine Execution Pattern Migration
engine.execute("SQL")2. Inspector Bind Execution Pattern
inspector.bind.execute("SQL")3. SQL Text Wrapping
connection.execute("raw SQL string")connection.execute(text("raw SQL string"))4. Parameter Binding Format
execute(sql, (param1, param2))(positional)execute(sql, {"name1": param1, "name2": param2})(named)5. Connection String Rendering
str(conn)for connection URLsconn.render_as_string(hide_password=False)6. URL Constructor Changes
URL(drivername, **params)URL.create(drivername, **params)7. Case Expression Syntax
sa.case([(condition, value)], else_=default)sa.case((condition, value), else_=default)8. Select Expression Syntax
sa.select([column1, column2])sa.select(column1, column2)9. Table Autoload Parameter
Table(name, metadata, autoload=True, autoload_with=engine)Table(name, metadata, autoload_with=engine)autoload=Trueis now implicit whenautoload_withis provided10. Subtransactions Removal
db.session.begin(subtransactions=True)db.session.begin()11. Custom Type Literal Processing
literal_processormethods to custom SQLAlchemy types for proper literal renderingDateandTimeStampcustom types12. Objects must be explicitly added to the session
Testing Improvements
Context Manager Mocking
Mock()toMagicMock()for proper__enter__/__exit__supportURL String Assertions
url.render_as_string(hide_password=False)instead ofstr(url)Files Modified
Core Changes:
superset/models/core.py- Connection string handlingsuperset/sql_lab.py- Query execution patternssuperset/utils/mock_data.py- Test data generationsuperset/utils/core.py- Utility functionssuperset/models/helpers.py- Query helperssuperset/extensions/metadb.py- Metadata handlingEngine Specifications:
Tests:
Backward Compatibility
All changes maintain full backward compatibility with SQLAlchemy 1.4.54. The patterns used (
with engine.connect(),text(), etc.) are available in SQLAlchemy 1.4.x when using future mode, ensuring a smooth transition path.Impact
This PR completes the upgrade to:
Benefits:
Testing
Breaking Changes
None for end users. All changes are internal implementation details that maintain the same external API and behavior.