diff --git a/alembic/script/revision.py b/alembic/script/revision.py index 587e9049..5825da34 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): 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 "