Reputation: 463
What is a good automatic/general way to check whether there are any data changes left 'dangling' and unflushed in SQLAlchemy at the conclusion of any request in Flask anywhere in the application?
In other words, I want to catch any SQLAlchemy model changes that are just "swept under the carpet" at the conclusion of request, because this suggests a bug in programming that is being concealed by the fact that the particular request is ending (and all uncommitted unflushed changes are destroyed with the session).
Flask-Sqlalchemy automatically destroys sessions when a request ends: http://flask.pocoo.org/docs/0.10/patterns/sqlalchemy/; and I assume this involves 'expiring' all unflushed changes: http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.Session.expire
(The reason I thought of this problem is that I temporarily turned autoflush ON, and suddenly on an API endpoint I saw that some model changes which I was not aware of, and were unintended were being flushed when a subsequent query later in the same API endpoint was run!)
Upvotes: 0
Views: 285