john-bodley opened a new pull request #10427: URL: https://github.com/apache/incubator-superset/pull/10427
### SUMMARY At Airbnb we've been running into issues with PyMySQL on Aurora MySQL 5.7. A Google search suggests the problem may be related to [thread safety](https://github.com/PyMySQL/PyMySQL/issues/425#issuecomment-179192376) and possibly that Apache Superset may not be leveraging SQLAlchemy's scoped sessions correctly. After grokking the code I realized that we were somewhat inconsistent with how we handle sessions with the metadata database. Ideally we should be leaning on the Flask-SQLAlchemy [scope session](https://github.com/pallets/flask-sqlalchemy/blob/master/src/flask_sqlalchemy/__init__.py#L727) which is safely removed on teardown. I noticed examples of where we created new sessions, or new scoped sessions which were only sometimes closed and/or removed. This PR simply ensures that all ORM interactions with the metadata database (and not the SQL Lab engines) use the `db.session` construct where `db` is the Flask-SQLAlchemy object. Also it seems redundant and adds unnecessary obfuscation to pass around the `db.session` and thus a number of function signatures have been updated. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF <!--- Skip this if not applicable --> ### TEST PLAN CI. ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ ] Has associated issue: - [ ] Changes UI - [ ] Requires DB Migration. - [ ] Confirm DB Migration upgrade and downgrade tested. - [ ] Introduces new feature or API - [ ] Removes existing feature or API ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
