From: Kim Wooseok Date: Tue, 28 Oct 2025 12:05:24 +0000 (-0400) Subject: Add colon (:) to invalid char for revision name add unittest X-Git-Tag: rel_1_17_1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5716f3354063a9b8f1e7f3c80941c0851fcf91d0;p=thirdparty%2Fsqlalchemy%2Falembic.git Add colon (:) to invalid char for revision name add unittest Disallow ':' character in custom revision identifiers. Previously, using a colon in a revision ID (e.g., 'REV:1') would create the revision, however revisions with colons in them are not correctly interpreted by other commands, as it overlaps with the revision range syntax. Pull request courtesy Kim Wooseok with original implementation by Hrushikesh Patil. Fixes: #1540 Closes: #1741 Pull-request: https://github.com/sqlalchemy/alembic/pull/1741 Pull-request-sha: 3894b1f9a1b1685a01465f53886af9086e23d079 Change-Id: Ie935f0e04981a0b3d0ac8a2ac03ffebce898280a --- 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 @@ _T = TypeVar("_T") _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..c0f8f0d2 --- /dev/null +++ b/docs/build/unreleased/1540.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, commands + :tickets: 1540 + + Disallow ':' character in custom revision identifiers. Previously, using a + colon in a revision ID (e.g., 'REV:1') would create the revision, however + revisions with colons in them are not correctly interpreted by other + commands, as it overlaps with the revision range syntax. Pull request + courtesy Kim Wooseok with original implementation by Hrushikesh Patil. \ 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 @@ class RevisionCommandTest(TestBase): 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 "