Skip to content

Commit ebcb67d

Browse files
authored
Chore: improve metadata update console printing (#3824)
1 parent 7b4157d commit ebcb67d

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

sqlmesh/core/console.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ def _show_summary_tree_for(
957957
)
958958
elif context_diff.indirectly_modified(name):
959959
indirect.add(f"[indirect]{display_name}")
960-
elif context_diff.metadata_updated(name):
960+
961+
if context_diff.metadata_updated(name):
961962
metadata.add(
962963
f"[metadata]{display_name}"
963964
if no_diff
@@ -1051,7 +1052,7 @@ def _show_categorized_snapshots(self, plan: Plan, default_catalog: t.Optional[st
10511052
if context_diff.directly_modified(snapshot.name):
10521053
category_str = SNAPSHOT_CHANGE_CATEGORY_STR[snapshot.change_category]
10531054
tree = Tree(
1054-
f"[bold][direct]Directly Modified: {snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)} ({category_str})"
1055+
f"\n[bold][direct]Directly Modified: {snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)} ({category_str})"
10551056
)
10561057
indirect_tree = None
10571058
for child_sid in sorted(plan.indirectly_modified.get(snapshot.snapshot_id, set())):
@@ -1069,13 +1070,16 @@ def _show_categorized_snapshots(self, plan: Plan, default_catalog: t.Optional[st
10691070
indirect_tree = self._limit_model_names(indirect_tree, self.verbose)
10701071
elif context_diff.metadata_updated(snapshot.name):
10711072
tree = Tree(
1072-
f"[bold][metadata]Metadata Updated: {snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)}"
1073+
f"\n[bold][metadata]Metadata Updated: {snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)}"
10731074
)
10741075
else:
10751076
continue
10761077

1077-
self._print(Syntax(context_diff.text_diff(snapshot.name), "sql", word_wrap=True))
1078-
self._print(tree)
1078+
text_diff = context_diff.text_diff(snapshot.name)
1079+
if text_diff:
1080+
self._print("")
1081+
self._print(Syntax(text_diff, "sql", word_wrap=True))
1082+
self._print(tree)
10791083

10801084
def _show_missing_dates(self, plan: Plan, default_catalog: t.Optional[str]) -> None:
10811085
"""Displays the models with missing dates."""

tests/integrations/jupyter/test_magics.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_diff(sushi_context, notebook, convert_all_html_output_to_text, get_all_
238238
assert len(output.outputs) == 2
239239
assert convert_all_html_output_to_text(output) == [
240240
"Differences from the `prod` environment:",
241-
"Models:\n── Directly Modified:\n └── sqlmesh_example.test",
241+
"Models:\n── Directly Modified:\n│ └── sqlmesh_example.test\n└── Metadata Updated:\n └── sqlmesh_example.test",
242242
]
243243
assert get_all_html_output(output) == [
244244
str(
@@ -266,7 +266,7 @@ def test_diff(sushi_context, notebook, convert_all_html_output_to_text, get_all_
266266
autoescape=False,
267267
)
268268
)
269-
+ "── "
269+
+ "── "
270270
+ str(
271271
h(
272272
"span",
@@ -275,6 +275,15 @@ def test_diff(sushi_context, notebook, convert_all_html_output_to_text, get_all_
275275
autoescape=False,
276276
)
277277
)
278+
+ "│ └── sqlmesh_example.test└── "
279+
+ str(
280+
h(
281+
"span",
282+
{"style": "font-weight: bold"},
283+
"Metadata Updated:",
284+
autoescape=False,
285+
)
286+
)
278287
+ " └── sqlmesh_example.test",
279288
autoescape=False,
280289
)

0 commit comments

Comments
 (0)