Skip to content

packaging: switch to PyMySQL and support SQLAlchemy 1.4/2.0#158

Open
dariusstefan wants to merge 13 commits intoOpenSIPS:masterfrom
dariusstefan:master
Open

packaging: switch to PyMySQL and support SQLAlchemy 1.4/2.0#158
dariusstefan wants to merge 13 commits intoOpenSIPS:masterfrom
dariusstefan:master

Conversation

@dariusstefan
Copy link
Copy Markdown
Contributor

@dariusstefan dariusstefan commented May 7, 2026

This PR addresses the cluster of packaging issues that prevent clean
installation on systems with newer versions of SQLAlchemy.

Changes

Also incorporates

Replaces

Eric Tamme and others added 13 commits May 7, 2026 15:34
- Wrap all conn.execute() string calls with text()
- Move declarative_base import to sqlalchemy.orm (SA 2.0)
- Replace autocommit execution_options with AUTOCOMMIT isolation level
- Catch ModuleNotFoundError in has_dialect() for SA 2.0 eager DBAPI load
- Preserve +pymysql driver suffix through URL reconstruction in
  get_db_url() so mysql+pymysql:// is never downgraded to mysql://
- Strip +driver suffix only where dialect name is compared against
  SUPPORTED_BACKENDS
- Rewrite sqlalchemy_utils shim to use connection-based API
- Fix pre-existing TypeError when inserting/updating integer values
Replace mysqlclient with PyMySQL (pure Python, no C compiler or
libmysqlclient-dev needed) and drop the <2 upper bound on SQLAlchemy,
unblocking installation from system packages on newer distros.

Closes OpenSIPS#149, OpenSIPS#152
Switch Debian and RPM packaging from mysqlclient to python3-pymysql.
Drop default-libmysqlclient-dev and mysql-devel build deps since PyMySQL
is pure Python and requires no C extension compilation.
No longer needed since PyMySQL is pure Python.
Update default database_url/database_admin_url values, documentation
examples and unit tests to use mysql+pymysql:// instead of mysql://.

Taken from PR OpenSIPS#157 (commit ecc1c98 by Jérôme Warnier).
The system-installed sqlalchemy-utils package varies a lot across distros
(0.36.x on Bullseye has a broken database_exists for PostgreSQL; 0.41.x is
required for SA 2.0 because the older versions still call the removed
engine.execute()). Forcing the vendored shim removes that variable.

Also fix database_exists()/drop_database() to connect to a system database
that is always present (information_schema for MySQL, postgres for
PostgreSQL) instead of database=None — psycopg2 does not honour None and
PyMySQL 1.4.x ignores it in some code paths, leaving the connection
pinned to the (possibly non-existent) target DB.
The vendored opensipscli/libs/sqlalchemy_utils shim is now the only code
path for database_exists()/drop_database(), so the external package is no
longer needed at install time. Remove it from pyproject.toml, setup.py,
the Debian control file, and the install/module documentation, and add
PyMySQL to the database module's documented dependencies.
Bullseye still ships SA 1.3.22 in stable. The vendored sqlalchemy_utils
shim and the declarative_base import in db.py both handle 1.3 alongside
1.4/2.0, so lower the pin so pip install works against the system SA on
older but still supported distros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to SQLAlchemy 2.0+ Package dependency failure on debian stable-slim

2 participants