5

When I run a Flask application which is using Flask-SQLAlchemy, it seems that Flask-SQLAlchemy is holding a session and when I issue a MySQL command, like alter table add column, in MySQL client terminal, the commands cannot be executed until I quit the Flask application.

Does anybody have similar experience? How can I issue commands on MySQL client without interrupting the Flask application?

1 Answer 1

9

You may want to look at this question SQL Alchemy Relationship loader leaves a lock on table?

What you'll need to do is subclass flask.ext.sqlalchemy.SQLAlchemy and override the apply_driver_hacks method to pass through the additional keyword argument isolation_level='READ <some level>':

from flask.ext.sqlalchemy import SQLAlchemy

class UnLockedAlchemy(SQLAlchemy):
    def apply_driver_hacks(self, app, info, options):
        if not "isolation_level" in options:
            options["isolation_level"] = "READ COMMITTED"  # For example
        return super(UnLockedAlchemy, self).apply_driver_hacks(app, info, options)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.