pytest-flask-sqlalchemy icon indicating copy to clipboard operation
pytest-flask-sqlalchemy copied to clipboard

Warning for every test since SQLAlchemy==1.3.17

Open VioletRainbows opened this issue 4 years ago • 5 comments

Description

In SQLAlchemy==1.3.17, a change was made (https://docs.sqlalchemy.org/en/13/changelog/changelog_13.html#change-7a6fdf5e0595f654572e4f8edb32b48c).

When using pytest, flask, sqlalchemy and pytest-flask-sqlalchemy, (requirements.txt) the following warning occurs for every test.

SAWarning: Reset agent is not active.  This should not occur unless there was already a connectivity error in progress.

This warning does not happen in the normal execution of the program.

Expected behavior

No warnings present.

How to reproduce

This issue can be reproduced with the code example here.

pytest output

$ pytest 
======================================= test session starts ========================================
platform linux -- Python 3.8.0, pytest-6.0.0, py-1.9.0, pluggy-0.13.1
rootdir: /home/mia/workspace/flaskdb, configfile: setup.cfg, testpaths: tests
plugins: mock-3.2.0, flask-sqlalchemy-1.0.2
collected 2 items                                                                                  

tests/test_flaskdb.py ..                                                                     [100%]

========================================= warnings summary =========================================
tests/test_flaskdb.py::test_insert_a
tests/test_flaskdb.py::test_insert_b
  /home/mia/.virtualenvs/flaskdb/lib/python3.8/site-packages/sqlalchemy/pool/base.py:884: SAWarning: Reset agent is not active.  This should not occur unless there was already a connectivity error in progress.
    util.warn(

-- Docs: https://docs.pytest.org/en/stable/warnings.html

VioletRainbows avatar Jul 29 '20 14:07 VioletRainbows

The _transaction fixture might have something to do with this.

I've noticed that removing the binds option here or removing the no-op stubs for close/rollback methods here allow the unit tests in the repro repo to pass without warnings appearing -- but those changes cause breakage in the pytest-flask-sqlalchemy unit tests.

jayaddison avatar Jul 30 '20 09:07 jayaddison

(NB: there's also a sqlalchemy mailing list thread describing some connection close and rollback behaviour that could be relevant - it's closely related to the changes that introduced this warning message - https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/sqlalchemy/Lit5HWFiC0U/y6nE-uksBAAJ)

jayaddison avatar Jul 30 '20 10:07 jayaddison

The linked pull request attempts to address these warnings but only removes them fully for sqlalchemy in master (i.e. version 1.4 onwards).

jayaddison avatar Jul 30 '20 11:07 jayaddison

Thanks for the report and the initial discussion here! This is one of those deep SA internal issues that I find to be somewhat inscrutable. I think I'd like to try to isolate the specific operation in the plugin that's raising this warning, and then try to get to the bottom of whether it's due to an actual problem (e.g. we're not rolling back sessions before closing them) or whether it's a side effect of the neccesary amount of kludgery in this plugin (in which case we should just figure out a way to suppress this warning).

jeancochrane avatar Aug 06 '20 17:08 jeancochrane

I also noticed this warning, in all my tests, which require db_session.

Is there a way I can help with fixing it?

citizen-stig avatar Oct 10 '20 13:10 citizen-stig