Skip to content

Commit 3d33cfa

Browse files
lachaibsqla-tester
authored andcommitted
refactor: add revision context to AutogenerateDiffsDetected so that wrappers may make other formatting of the diff
### Description As discussed in #1597, AutogenerateDiffsDetected should hold contextual information so that command can be wrapped for another format (CI, pre-commit hook...) ### Checklist <!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once) --> This pull request is: - [ ] A documentation / typographical error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #<issue number>` in the commit message - please include tests. **Have a nice day!** Closes: #1598 Pull-request: #1598 Pull-request-sha: 7799320 Change-Id: Id08bc52a0586063f177736a36a61f96232459f1c
1 parent 980bd91 commit 3d33cfa

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

alembic/command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ def retrieve_migrations(rev, context):
298298

299299
if diffs:
300300
raise util.AutogenerateDiffsDetected(
301-
f"New upgrade operations detected: {diffs}"
301+
f"New upgrade operations detected: {diffs}",
302+
revision_context=revision_context,
303+
diffs=diffs,
302304
)
303305
else:
304306
config.print_stdout("No new upgrade operations detected.")

alembic/util/exc.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
from typing import List
5+
from typing import Tuple
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from alembic.autogenerate import RevisionContext
10+
11+
112
class CommandError(Exception):
213
pass
314

415

516
class AutogenerateDiffsDetected(CommandError):
6-
pass
17+
def __init__(
18+
self,
19+
message: str,
20+
revision_context: RevisionContext,
21+
diffs: List[Tuple[Any, ...]],
22+
) -> None:
23+
super().__init__(message)
24+
self.revision_context = revision_context
25+
self.diffs = diffs
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. change::
2+
:tags: check, autogenerate
3+
:tickets: 1597
4+
5+
Add revision context to AutogenerateDiffsDetected so that command can be wrapped and diffs may be output in a different format.
6+
Pull request courtesy of Louis-Amaury Chaib (@lachaib).

0 commit comments

Comments
 (0)