add rev_id generator function feature to environment.configure(), will apply to revision, merge
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 55/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- python, sqlalchemy
- Ambito
- backend-api-design, database
Direzione di ricerca
Inizia in alembic/command.py, confrontando revision() intorno alle righe 194-320 con merge() intorno alle righe 382-439. Traccia il modo in cui merge() costruisce il proprio RevisionContext e il modo in cui alembic/autogenerate/api.py gestisce process_revision_directives. Il lavoro è completato quando l’API merge accetta e inoltra il callback opzionale in modo coerente, con una copertura per il nuovo parametro e preservando il comportamento esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the use case
The merge command should support the process_revision_directives parameter in its programmatic API, consistent with the revision command.
Currently, while both commands support revision_environment (which runs env.py), only the revision command accepts a programmatic process_revision_directives parameter. This creates an API
inconsistency when using Alembic programmatically to customize revision generation logic for merge operations.
Databases / Backends / Drivers targeted
All databases - this is a general Alembic API feature request.
Example Use
Current behavior - revision command (works):
from alembic import command
from alembic.config import Config
config = Config("alembic.ini")
def my_process_revision_directives(context, revision, directives):
"""Custom revision ID generation logic"""
for directive in directives:
directive.rev_id = generate_custom_id() # Custom logic
This works - process_revision_directives parameter is supported
command.revision(
config,
message="Add new feature",
process_revision_directives=my_process_revision_directives
)
Desired behavior - merge command (currently doesn't work):
# This fails with TypeError - process_revision_directives is not accepted
command.merge(
config,
revisions=("head1", "head2"),
message="Merge branches",
process_revision_directives=my_process_revision_directives # ❌ Not supported
)
Current workaround:
Users must configure the hook in env.py, which affects all operations:
# env.py
def process_revision_directives(context, revision, directives):
# This applies to ALL revision/merge commands
for directive in directives:
directive.rev_id = generate_custom_id()
context.configure(
process_revision_directives=process_revision_directives
)
This workaround doesn't allow per-command customization when using the programmatic API.
Proposed API:
def merge(
config: Config,
revisions: _RevIdType,
message: Optional[str] = None,
branch_label: Optional[_RevIdType] = None,
rev_id: Optional[str] = None,
process_revision_directives: Optional[ProcessRevisionDirectiveFn] = None, # NEW
) -> Optional[Script]:
"""
:param process_revision_directives: optional callable that allows
programmatic customization of the revision directives. Same signature
as the callable described at
:paramref:`.EnvironmentContext.configure.process_revision_directives`
"""
# Implementation already uses RevisionContext internally,
# just need to accept and pass through the parameter
Use cases:
- Different logic for merges vs regular revisions: Apply special revision ID schemes or metadata only to merge commits
- CI/CD automation: Programmatic scripts that customize merge behavior without modifying env.py
- Multi-tenant environments: Different revision ID generation based on runtime context
Additional context
- The merge command already uses RevisionContext internally (since 1.12.0 when revision_environment support was added via #1299)
- The implementation would be minimal - just accepting and passing through the parameter
- This would make the API consistent between revision and merge commands
- The parameter would be optional and backward-compatible
Reference:
- alembic/command.py::revision() - Lines 194-320 (already supports this parameter)
- alembic/command.py::merge() - Lines 382-439 (should support this parameter)
- alembic/autogenerate/api.py::RevisionContext - Already supports process_revision_directives
Versions.
- OS: macOS (but applies to all platforms)
- Python: 3.9+
- Alembic: 1.16.5 (latest)
- SQLAlchemy: 1.4+/2.0+
- Database: All
- DBAPI: All
- Lingua principale
- Python
- Stelle
- 4.5k
- Fork
- 391
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sqlalchemy/alembic
-
on_version_apply is typed as a positional callable, but alembic calls it with keyword argumentsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
sqlalchemy/alembic#1883 · 1 commento ·
-
Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated scriptForse di nuovo libera @ApparentlyTejas l’ha presa 21 giorni fa e non c’è nessuna pull request aperta. Apertabug command interface
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
sqlalchemy/alembic#1879 · 3 commenti ·
-
bug pep 484
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
sqlalchemy/alembic#1341 · 2 commenti ·
-
autogenerate - detection bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
sqlalchemy/alembic#1121 · 3 commenti ·
-
Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertaautogenerate - defaults bug regression
Difficoltà 3/5 1-2 giorni Idoneità per principianti 50/100
sqlalchemy/alembic#1877 · 1 commento ·
Tutte le issue di sqlalchemy/alembic
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Cygnux-Labs/Tracekit#827 ·
I maintainer di solito rispondono entro 1 giorno
-
SPIDevice selects an active-high device as soon as it is createdForse già presa @mikeysklar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
adafruit/circuitpython#11869 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
glossyio/traffic-monitor#312 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
narwhals-dev/narwhals#4154 ·
I maintainer di solito rispondono entro 1 giorno