Entry point for DefaultImpl subclasses? (or, just use plugins?)

Abierto
#1,874 1 comentario 0 reacciones 0 asignados Ver en GitHub

@dwreeves ya está trabajando en esto.

Desde el 4/10/2026.

  • #1875 de @dwreeves — abierto

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python, sqlalchemy
Área
tooling

Línea de trabajo

Review Alembic's existing plugin ecosystem and the linked pull request #1875, then compare that approach with the proposed alembic.implementations entry point. Done means the project has a clear decision on registration order and whether the existing plugin pattern should be documented or a new entry point supported.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

code review in progress migration environment use case
Discussed in https://github.com/sqlalchemy/alembic/discussions/1872

Originally posted by dwreeves September 30, 2026
Hello,

I could not find any discussion on this elsewhere.

I'm wondering if it would make sense for Alembic to support entry-points for Defaultmpl subclasses.


Right now, it looks like the pattern some third-party providers use (e.g. sqlalchemy-redshift) is to load the impl as a side-effect of importing the SqlAlchemy dialect module entry-point.

There are two advantages of an entry-point. The first would be not needing to import Alembic or register anything during the normal runtime of the application. Not usually a big deal to have Alembic in the sys modules, but could be nice-to-have for custom dialects.

The second is a little more subtle, but the entry-point invocation could control the order of registration of dialects, so that the env.py's dialect is guaranteed to resolve last.

The second is actually relevant to a PR I have open for snowflake-sqlalchemy: right now there is no guarantee of whether the library provided SnowflakeImpl will resolve before or after a user's custom implementation; it's totally dependent on the env.py's imports. If entry-points are respected however, then Alembic can always resolve entry-points before env.py runs, guaranteeing user-generated DefaultImpls are resolved last. https://github.com/snowflakedb/snowflake-sqlalchemy/issues/758


So e.g. I have a SQLAlchemy driver for MyCoolSqlDatabase, I could structure like this:

pyproject.toml
src/
  mycoolsqldatabase_sqlalchemy/
    __init__.py
    dialect.py
    alembic.py
# pyproject.toml
[project.entry-points."sqlalchemy.dialects"]
mycoolsqldatabase = "mycoolsqldatabase_sqlalchemy:dialect"

[project.entry-points."alembic.implementations"]
mycoolsqldatabase = "mycoolsqldatabase_sqlalchemy:alembic"  # alternatively mycoolsqldatabase_sqlalchemy.alembic:MyCoolSqlDatabaseImpl

An argument against this--

I am aware that Alembic uses entry-points for plugins.

Perhaps the pattern you might suggest is to create a plugin with an empty setup() that registers the Alembic impl as a side-effect? E.g.

# plugin.py
from alembic.ddl.impl import DefaultImpl

class MyCoolSqlDatabaseImpl(DefaultImpl):
    __dialect__ = "my_cool_sql_database"

def setup(plugin):
    pass

If so, it may make sense to show that as an example in the documentation. If that is guaranteed to resolve before env.py, then that could also work as a path for the aforementioned PR.

I think the upside to using the existing plugin ecosystem is that it reduces the API surface on Alembic's end, but the downside is this is very cheeky and not intuitive, especially without a documented example.


Lastly, thanks for the awesome ecosystem, zzzeeek.

Lenguaje dominante
Python
Estrellas
4.5k
Forks
391
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sqlalchemy/alembic

Todos los issues de sqlalchemy/alembic

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.