Skip to content

Commit b9b5e45

Browse files
authored
Refactor: allow overriding is_breaking_change in categorize_change (#3178)
1 parent d77f555 commit b9b5e45

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

sqlmesh/core/snapshot/categorizer.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99

1010
def categorize_change(
11-
new: Snapshot, old: Snapshot, config: t.Optional[CategorizerConfig] = None
11+
new: Snapshot,
12+
old: Snapshot,
13+
config: t.Optional[CategorizerConfig] = None,
14+
is_breaking_change: t.Optional[t.Callable[..., t.Optional[bool]]] = None,
15+
**kwargs: t.Any,
1216
) -> t.Optional[SnapshotChangeCategory]:
1317
"""Attempts to automatically categorize a change between two snapshots.
1418
@@ -19,6 +23,10 @@ def categorize_change(
1923
Args:
2024
new: The new snapshot.
2125
old: The old snapshot.
26+
config: Configuration for the automatic categorizer of snapshot changes.
27+
is_breaking_change: Callable that compares two models (new, old) and determines
28+
whether there is a breaking change between them.
29+
kwargs: Additional arguments to pass to is_breaking_change.
2230
2331
Returns:
2432
The change category or None if the category can't be determined automatically.
@@ -48,11 +56,14 @@ def categorize_change(
4856
return SnapshotChangeCategory.NON_BREAKING
4957
return None
5058

51-
is_breaking_change = new_model.is_breaking_change(old_model)
52-
if is_breaking_change is None:
59+
breaking_change = (
60+
is_breaking_change(new_model, old_model, **kwargs)
61+
if is_breaking_change
62+
else new_model.is_breaking_change(old_model)
63+
)
64+
if breaking_change is None:
5365
return default_category
66+
5467
return (
55-
SnapshotChangeCategory.BREAKING
56-
if is_breaking_change
57-
else SnapshotChangeCategory.NON_BREAKING
68+
SnapshotChangeCategory.BREAKING if breaking_change else SnapshotChangeCategory.NON_BREAKING
5869
)

0 commit comments

Comments
 (0)