aiondemand / AIOD-rest-api

A containerized application using FastAPI and SQLAlchemy connected to a MySQL database.
MIT License
10 stars 7 forks source link

Dependency update - mysqlclient v2.2.1 failing on MacOS #324

Open jsmatias opened 2 months ago

jsmatias commented 2 months ago

All the unit tests started failing on the following system due to current mysqlclient v.2.2.1:

ProductName: macOS ProductVersion: 14.4.1 BuildVersion: 23E224

Full error:

py::test_get_all_happy_path failed with error: Test failed with exception
deletion_triggers = <class 'database.model.concept.concept.AIoDConcept'>
    @pytest.fixture(scope="session")
    def engine(deletion_triggers) -> Iterator[Engine]:
        """
        Create a SqlAlchemy engine for tests, backed by a temporary sqlite file.
        """
        temporary_file = tempfile.NamedTemporaryFile()
        engine = create_engine(f"sqlite:///{temporary_file.name}?check_same_thread=False")
        AIoDConcept.metadata.create_all(engine)
>       EngineSingleton().patch(engine)
src/tests/testutils/default_sqlalchemy.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/database/session.py:21: in __init__
    self.engine = create_engine(db_url(), echo=False, pool_recycle=3600)
venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py:281: in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
venv/lib/python3.11/site-packages/sqlalchemy/engine/create.py:599: in create_engine
    dbapi = dbapi_meth(**dbapi_args)
venv/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/mysqldb.py:147: in import_dbapi
    return __import__("MySQLdb")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    """
    MySQLdb - A DB API v2.0 compatible interface to MySQL.

    This package is a wrapper around _mysql, which mostly implements the
    MySQL C API.

    connect() -- connects to server

    See the C API specification and the MySQL documentation for more info
    on other items.

    For information on how MySQLdb handles type conversion, see the
    MySQLdb.converters module.
    """

    from .release import version_info
>   from . import _mysql
E   ImportError: dlopen(/Users/jmatias/Documents/develop/AIOD-rest-api/venv/lib/python3.11/site-packages/MySQLdb/_mysql.cpython-311-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/mysql/lib/libmysqlclient.22.dylib
E     Referenced from: <094163CF-9660-37E3-978E-50FE60955C55> /Users/jmatias/Documents/develop/AIOD-rest-api/venv/lib/python3.11/site-packages/MySQLdb/_mysql.cpython-311-darwin.so
E     Reason: tried: '/opt/homebrew/opt/mysql/lib/libmysqlclient.22.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/mysql/lib/libmysqlclient.22.dylib' (no such file), '/opt/homebrew/opt/mysql/lib/libmysqlclient.22.dylib' (no such file), '/opt/homebrew/Cellar/mysql/8.3.0_1/lib/libmysqlclient.22.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/mysql/8.3.0_1/lib/libmysqlclient.22.dylib' (no such file), '/opt/homebrew/Cellar/mysql/8.3.0_1/lib/libmysqlclient.22.dylib' (no such file)
venv/lib/python3.11/site-packages/MySQLdb/__init__.py:17: ImportError

Solution: Updating it to the most recent version (mysqlclient==v2.2.4) solves the issue for this platform.