SQLAlchemy 2.0 breaks package sqlalchemy-migrate.

Bug #2004009 reported by Jorge San Emeterio
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Triaged
Undecided
Unassigned

Bug Description

Description
===========
The SQLAlchemy package has recently had a major update, moving its version up to 2.0. Problem is, the change seems to break compatibility with version 1 of the library as now the sqlalchemy-migrate package, which is dependent on it, is reporting missing modules, thus breaking down. Now, the thing is that SQLAlchemy's requirement is the following: 'SQLAlchemy>=1.4.13', which will install the newest version of the package. This requirement needs to be constraint so that it never leaves major version 1.

Here is an excerpt of the error message reported by sqlalchemy-migrate:
"""
Failed to import test module: nova.tests.unit.volume.test_cinder
Traceback (most recent call last):
  File "/usr/lib64/python3.11/unittest/loader.py", line 407, in _find_test_path
    module = self._get_module_from_name(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/unittest/loader.py", line 350, in _get_module_from_name
    __import__(name)
  File "/.../nova/tests/unit/volume/test_cinder.py", line 30, in <module>
    from nova import test
  File "/.../nova/test.py", line 65, in <module>
    from nova.tests import fixtures as nova_fixtures
  File "/.../nova/tests/fixtures/__init__.py", line 16, in <module>
    from .cinder import CinderFixture # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../nova/tests/fixtures/cinder.py", line 24, in <module>
    from nova.tests.fixtures import nova as nova_fixtures
  File "/.../nova/tests/fixtures/nova.py", line 56, in <module>
    from nova.db import migration
  File "/.../nova/db/migration.py", line 22, in <module>
    from migrate import exceptions as migrate_exceptions
  File "/.../.venv/lib64/python3.11/site-packages/migrate/__init__.py", line 11, in <module>
    from migrate.changeset import *
  File "/.../.venv/lib64/python3.11/site-packages/migrate/changeset/__init__.py", line 21, in <module>
    from migrate.changeset.schema import *
  File "/.../.venv/lib64/python3.11/site-packages/migrate/changeset/schema.py", line 20, in <module>
    from migrate.changeset.databases.visitor import (get_engine_visitor,
  File "/.../.venv/lib64/python3.11/site-packages/migrate/changeset/databases/visitor.py", line 7, in <module>
    from migrate.changeset.databases import (sqlite,
  File "/.../.venv/lib64/python3.11/site-packages/migrate/changeset/databases/sqlite.py", line 13, in <module>
    from sqlalchemy.databases import sqlite as sa_base
ModuleNotFoundError: No module named 'sqlalchemy.databases'
"""

Here is some information about the SQLAlchemy's new update:
https://www.sqlalchemy.org/blog/2023/01/26/sqlalchemy-2.0.0-released/

Steps to reproduce
==================
1.- python -m venv .venv
2.- . .venv/bin/activate
3.- pip install -e . -r requirements.txt -r test-requirements.txt
4.- python -m unittest discover -p test_* -s .

Expected result
===============
ModuleNotFoundError exception does not happen.

Actual result
=============
Execution of the test discovery is interrupted due to the error.

Environment
===========
Fedora Linux 37 (Workstation Edition) x86_64
Python 3.11.1

Revision history for this message
Joris Vleminckx (jvleminc) wrote (last edit ):

Same issue seems to happen in glance.

To fix it there I had to pin "tox" to a version < 4.0 and to pin "sqlalchemy" to a version <2.0 in the repo's main "requirements.txt".

Uggla (rene-ribaud)
Changed in nova:
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.