Skip to content

Commit

Permalink
refactor: add revision context to AutogenerateDiffsDetected so that w…
Browse files Browse the repository at this point in the history
…rappers may make other formatting of the diff

fixes: #1597
  • Loading branch information
lachaib committed Jan 31, 2025
1 parent 980bd91 commit ee7d8de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion alembic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ def retrieve_migrations(rev, context):

if diffs:
raise util.AutogenerateDiffsDetected(
f"New upgrade operations detected: {diffs}"
f"New upgrade operations detected: {diffs}",
revision_context=revision_context,
)
else:
config.print_stdout("No new upgrade operations detected.")
Expand Down
12 changes: 11 additions & 1 deletion alembic/util/exc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from alembic.autogenerate import RevisionContext


class CommandError(Exception):
pass


class AutogenerateDiffsDetected(CommandError):
pass
def __init__(
self, message: str, revision_context: "RevisionContext"
) -> None:
super().__init__(message)
self.revision_context = revision_context
6 changes: 6 additions & 0 deletions docs/build/unreleased/issue1597.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. change::
:tags: check, autogenerate
:tickets: 1597

Add revision context to AutogenerateDiffsDetected so that command can be wrapped and diffs may be output in a different format.
Pull request courtesy of Louis-Amaury Chaib (@lachaib).

0 comments on commit ee7d8de

Please sign in to comment.