From 21603f1eff4c033bd8462bf2a8efab17caa6cd5e Mon Sep 17 00:00:00 2001 From: PatilHrushikesh Date: Sun, 22 Sep 2024 23:14:55 +0530 Subject: [PATCH 1/2] Add colon (:) to invalid char for revision name As colon is used in revision range, it shouldn't be used in revision name --- alembic/script/revision.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic/script/revision.py b/alembic/script/revision.py index c3108e98..f68fc954 100644 --- a/alembic/script/revision.py +++ b/alembic/script/revision.py @@ -45,7 +45,7 @@ _TR = TypeVar("_TR", bound=Optional[_RevisionOrStr]) _relative_destination = re.compile(r"(?:(.+?)@)?(\w+)?((?:\+|-)\d+)") -_revision_illegal_chars = ["@", "-", "+"] +_revision_illegal_chars = ["@", "-", "+", ":"] class _CollectRevisionsProtocol(Protocol): From 3894b1f9a1b1685a01465f53886af9086e23d079 Mon Sep 17 00:00:00 2001 From: Kim Wooseok Date: Tue, 28 Oct 2025 17:07:47 +0900 Subject: [PATCH 2/2] fix: disallow ':' in custom revision IDS (#1541) --- docs/build/unreleased/1540.rst | 7 +++++++ tests/test_script_production.py | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 docs/build/unreleased/1540.rst diff --git a/docs/build/unreleased/1540.rst b/docs/build/unreleased/1540.rst new file mode 100644 index 00000000..3c42fe77 --- /dev/null +++ b/docs/build/unreleased/1540.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: usecase, revision + :tickets: 1540 + + Disallow ':' character in custom revision identifiers. Previously, using a colon in + a revision ID (e.g., 'REV:1') caused alembic to interpret it as a revision range, + resulting in upgrade failures. \ No newline at end of file diff --git a/tests/test_script_production.py b/tests/test_script_production.py index 00150468..853767dc 100644 --- a/tests/test_script_production.py +++ b/tests/test_script_production.py @@ -393,6 +393,16 @@ def test_illegal_revision_chars(self): rev_id="no@atsigns", ) + assert_raises_message( + util.CommandError, + r"Character\(s\) ':' not allowed in " + "revision identifier 'no:colons'", + command.revision, + self.cfg, + message="some message", + rev_id="no:colons", + ) + assert_raises_message( util.CommandError, r"Character\(s\) '-, @' not allowed in revision "