Skip to content

Commit 883786a

Browse files
committed
Fix(cicd_bot): Don't truncate backfill model list
1 parent 317df56 commit 883786a

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

sqlmesh/core/console.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,9 @@ class MarkdownConsole(CaptureTerminalConsole):
31073107
AUDIT_PADDING = 7
31083108

31093109
def __init__(self, **kwargs: t.Any) -> None:
3110-
super().__init__(**{**kwargs, "console": RichConsole(no_color=True)})
3110+
super().__init__(
3111+
**{**kwargs, "console": RichConsole(no_color=True, width=kwargs.pop("width", None))}
3112+
)
31113113

31123114
def show_environment_difference_summary(
31133115
self,

sqlmesh/integrations/github/cicd/command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
@click.pass_context
2929
def github(ctx: click.Context, token: str) -> None:
3030
"""Github Action CI/CD Bot. See https://sqlmesh.readthedocs.io/en/stable/integrations/github/ for details"""
31-
set_console(MarkdownConsole())
31+
# set a larger width because if none is specified, it auto-detects 80 characters when running in GitHub Actions
32+
# which can result in surprise newlines when outputting dates to backfill
33+
set_console(MarkdownConsole(width=1000))
3234
ctx.obj["github"] = GithubController(
3335
paths=ctx.obj["paths"],
3436
token=token,

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ def _append_output(cls, key: str, value: str) -> None:
485485
print(f"{key}={value}", file=fh)
486486

487487
def get_plan_summary(self, plan: Plan) -> str:
488+
# use Verbosity.VERY_VERBOSE to prevent the list of models from being truncated
489+
# this is particularly importanmt for the "Models needing backfill" list because
490+
# there is no easy way to tell this otherwise
491+
orig_verbosity = self._console.verbosity
492+
self._console.verbosity = Verbosity.VERY_VERBOSE
493+
488494
try:
489495
# Clear out any output that might exist from prior steps
490496
self._console.clear_captured_outputs()
@@ -517,7 +523,10 @@ def get_plan_summary(self, plan: Plan) -> str:
517523

518524
return f"{difference_summary}\n{missing_dates}{plan_flags_section}"
519525
except PlanError as e:
526+
logger.exception("Plan failed to generate")
520527
return f"Plan failed to generate. Check for pending or unresolved changes. Error: {e}"
528+
finally:
529+
self._console.verbosity = orig_verbosity
521530

522531
def run_tests(self) -> t.Tuple[ModelTextTestResult, str]:
523532
"""

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# type: ignore
2+
import typing as t
23
import os
34
import pathlib
45
from unittest import mock
@@ -17,6 +18,7 @@
1718
BotCommand,
1819
MergeStateStatus,
1920
)
21+
from sqlmesh.integrations.github.cicd.controller import GithubController
2022
from sqlmesh.integrations.github.cicd.command import _update_pr_environment
2123
from sqlmesh.utils.date import to_datetime, now
2224
from tests.integrations.github.cicd.conftest import MockIssueComment
@@ -591,3 +593,39 @@ def test_uncategorized(
591593
assert "The following models could not be categorized automatically" in summary
592594
assert '- "b"' in summary
593595
assert "Run `sqlmesh plan hello_world_2` locally to apply these changes" in summary
596+
597+
598+
def test_get_plan_summary_doesnt_truncate_backfill_list(
599+
github_client, make_controller: t.Callable[..., GithubController]
600+
):
601+
controller = make_controller(
602+
"tests/fixtures/github/pull_request_synchronized.json",
603+
github_client,
604+
mock_out_context=False,
605+
)
606+
607+
summary = controller.get_plan_summary(controller.prod_plan)
608+
609+
assert "more ...." not in summary
610+
611+
assert (
612+
"""**Models needing backfill:**
613+
* `memory.raw.demographics`: [full refresh]
614+
* `memory.sushi.active_customers`: [full refresh]
615+
* `memory.sushi.count_customers_active`: [full refresh]
616+
* `memory.sushi.count_customers_inactive`: [full refresh]
617+
* `memory.sushi.customer_revenue_by_day`: [2025-06-30 - 2025-07-06]
618+
* `memory.sushi.customer_revenue_lifetime`: [2025-06-30 - 2025-07-06]
619+
* `memory.sushi.customers`: [full refresh]
620+
* `memory.sushi.items`: [2025-06-30 - 2025-07-06]
621+
* `memory.sushi.latest_order`: [full refresh]
622+
* `memory.sushi.marketing`: [2025-06-30 - 2025-07-06]
623+
* `memory.sushi.order_items`: [2025-06-30 - 2025-07-06]
624+
* `memory.sushi.orders`: [2025-06-30 - 2025-07-06]
625+
* `memory.sushi.raw_marketing`: [full refresh]
626+
* `memory.sushi.top_waiters`: [recreate view]
627+
* `memory.sushi.waiter_as_customer_by_day`: [2025-06-30 - 2025-07-06]
628+
* `memory.sushi.waiter_names`: [full refresh]
629+
* `memory.sushi.waiter_revenue_by_day`: [2025-06-30 - 2025-07-06]"""
630+
in summary
631+
)

0 commit comments

Comments
 (0)