mozilla/ichnaea

Update to SQLAlchemy 1.4

jwhitlock opened this issue · 2 comments

SQLAlchemy 1.4 is a big release, and meant as a transition to a bigger 2.0 release:

There have been several point releases in quick succession, from 1.4.3 on March 25 to 1.4.11 on April 21, with 1.4.12 in planning. It may be worth letting others shake out more issues before adopting it.

Tests now pass in both SQLAlchemy 1.3 and 1.4, with 51 warnings (all the same?):

ichnaea/api/locate/tests/test_locate_v1.py: 23 warnings
ichnaea/api/locate/tests/test_region_v1.py: 9 warnings
ichnaea/api/submit/tests/test_submit_v0.py: 1 warning
ichnaea/api/submit/tests/test_submit_v1.py: 1 warning
ichnaea/api/submit/tests/test_submit_v2.py: 1 warning
ichnaea/content/tests/test_views.py: 5 warnings
ichnaea/models/tests/test_blue.py: 2 warnings
ichnaea/models/tests/test_cell.py: 4 warnings
ichnaea/models/tests/test_content.py: 3 warnings
ichnaea/models/tests/test_wifi.py: 2 warnings
  /usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py:2378: SAWarning: transaction already deassociated from connection
    util.warn("transaction already deassociated from connection")

To see where the warning is emitted in make testshell:

python -W error -m pytest -sx

which gives this traceback in the teardown of TestView.test_api_key_limit:

Traceback (most recent call last):
  File "/app/ichnaea/conftest.py", line 248, in independent_session
    trans.rollback()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2244, in rollback
    self._do_rollback()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2434, in _do_rollback
    self._close_impl(try_deactivate=True)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2423, in _close_impl
    self._deactivate_from_connection()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2378, in _deactivate_from_connection
    util.warn("transaction already deassociated from connection")
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 1617, in warn
    warnings.warn(msg, exc.SAWarning, stacklevel=2)
sqlalchemy.exc.SAWarning: transaction already deassociated from connection

SQLAlchemy 1.4.14 requires a cache_ok class member to mark if a custom type is safe or not as a key for SQL compilation caching, and raises a warning if omitted. It appears to have no effect in 1.4.13 and earlier, including SQLAlchemy 1.3, so we can add them. PR #1596 fixes some, more are needed.

Somewhere between 1.4.11 and 1.4.12, a test began failing. It may be related to the warning about sqlalchemy.exc.SAWarning: transaction already deassociated from connection. This does not happen every time independent session is used, but I haven't identified the pattern yet.