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: sqlalchemy#1597
  • Loading branch information
lachaib committed Feb 1, 2025
1 parent 980bd91 commit 7799320
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion alembic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ 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,
diffs=diffs,
)
else:
config.print_stdout("No new upgrade operations detected.")
Expand Down
21 changes: 20 additions & 1 deletion alembic/util/exc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
from __future__ import annotations

from typing import Any
from typing import List
from typing import Tuple
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,
diffs: List[Tuple[Any, ...]],
) -> None:
super().__init__(message)
self.revision_context = revision_context
self.diffs = diffs
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 7799320

Please sign in to comment.