add rev_id generator function feature to environment.configure(), will apply to revision, merge
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 55/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python, sqlalchemy
調査の方向性
alembic/command.py から始め、194-320 行付近の revision() と 382-439 行付近の merge() を比較します。merge() がどのように RevisionContext を構築するか、また alembic/autogenerate/api.py が process_revision_directives をどのように処理するかを追跡します。完了条件は、merge API がオプションのコールバックを一貫して受け取り転送し、新しいパラメーターのカバレッジを追加しつつ、既存の動作を維持することです。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 4.5k
- フォーク
- 391
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sqlalchemy/alembic のほかの issue
-
on_version_apply is typed as a positional callable, but alembic calls it with keyword arguments再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sqlalchemy/alembic#1883 · コメント 1 件 ·
-
Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated script再び着手できるかも @ApparentlyTejas が 21 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug command interface
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
sqlalchemy/alembic#1879 · コメント 3 件 ·
-
bug pep 484
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
sqlalchemy/alembic#1341 · コメント 2 件 ·
-
autogenerate - detection bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
sqlalchemy/alembic#1121 · コメント 3 件 ·
-
Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンautogenerate - defaults bug regression
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
sqlalchemy/alembic#1877 · コメント 1 件 ·
sqlalchemy/alembic の issue をすべて見る
似ている issue
-
fleet size/m
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sipyourdrink-ltd/bernstein#7548 ·
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted level 1 wocs
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
GianlucaBave/murmury#73 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
G-nn-r/lg_heatpump#52 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
agno-agi/agno#11657 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
category:codebase:gpi category:codebase:handle type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信