In my project I have some idle_in_transaction sessions the source of which I can't find. I have custom base_query which is a child of the BaseQuery with the only modification being one additional .filter(). It seems that db.session.query and models.ModelName.query use the same session (based on the pg_stat_activity table), but looking at the code of flask-sqlalchemy and sqlalchemy it is not obvious for me. As far as I understood, db.session is a scoped session, and model query class uses default SQLAlchemy session. Do they really use the same session? If not, this would explain why I have idle_in_transaction sessions