Skip to content

Commit 86d6d42

Browse files
authored
Bug/py compatibility (#5644)
Signed-off-by: AvinashYerra <101195675+AvinashYerra@users.noreply.github.com>
1 parent 278757c commit 86d6d42

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

sqlmesh/magics.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ def wrapper(self: SQLMeshMagics, *args: t.Any, **kwargs: t.Any) -> None:
9595
return wrapper
9696

9797

98+
def parse_expand(value: str) -> t.Union[bool, t.List[str]]:
99+
if value.lower() == "true":
100+
return True
101+
if value.lower() == "false":
102+
return False
103+
return [name.strip() for name in value.split(",") if name.strip()]
104+
105+
98106
def format_arguments(func: t.Callable) -> t.Callable:
99107
"""Decorator to add common format arguments to magic commands."""
100108
func = argument(
@@ -633,8 +641,8 @@ def evaluate(self, context: Context, line: str) -> None:
633641
@argument("--execution-time", type=str, help="Execution time.")
634642
@argument(
635643
"--expand",
636-
type=t.Union[bool, t.Iterable[str]],
637-
help="Whether or not to use expand materialized models, defaults to False. If True, all referenced models are expanded as raw queries. If a list, only referenced models are expanded as raw queries.",
644+
type=parse_expand,
645+
help="Whether or not to use expand materialized models, defaults to False. If 'true', all referenced models are expanded as raw queries. If a comma-separated list of model names, only those models are expanded as raw queries.",
638646
)
639647
@argument("--dialect", type=str, help="SQL dialect to render.")
640648
@argument("--no-format", action="store_true", help="Disable fancy formatting of the query.")
@@ -647,6 +655,7 @@ def render(self, context: Context, line: str) -> None:
647655
render_opts = vars(parse_argstring(self.render, line))
648656
model = render_opts.pop("model")
649657
dialect = render_opts.pop("dialect", None)
658+
expand = render_opts.pop("expand", False)
650659

651660
model = context.get_model(model, raise_if_missing=True)
652661

@@ -655,7 +664,7 @@ def render(self, context: Context, line: str) -> None:
655664
start=render_opts.pop("start", None),
656665
end=render_opts.pop("end", None),
657666
execution_time=render_opts.pop("execution_time", None),
658-
expand=render_opts.pop("expand", False),
667+
expand=expand,
659668
)
660669

661670
no_format = render_opts.pop("no_format", False)

0 commit comments

Comments
 (0)