Skip to content

Commit

Permalink
Feat: add this_model property in the macro evaluator to return a stri…
Browse files Browse the repository at this point in the history
…ng (#3528)
  • Loading branch information
georgesittas authored Dec 18, 2024
1 parent 2102cc1 commit d6be17c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqlmesh/core/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ def runtime_stage(self) -> RuntimeStage:
"""Returns the current runtime stage of the macro evaluation."""
return self.locals["runtime_stage"]

@property
def this_model(self) -> str:
"""Returns the resolved name of the surrounding model."""
this_model = self.locals.get("this_model")
if not this_model:
raise SQLMeshError("Model name is not available in the macro evaluator.")
return this_model.sql(dialect=self.dialect, identify=True, comments=False)

@property
def engine_adapter(self) -> EngineAdapter:
engine_adapter = self.locals.get("engine_adapter")
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5050,6 +5050,7 @@ def this_model_resolves_to_quoted_table(evaluator):
return not this_model or (
isinstance(this_model, exp.Table)
and this_model.sql(dialect=evaluator.dialect, comments=False) == expected_name
and evaluator.this_model == expected_name
)

expressions = d.parse(
Expand Down

0 comments on commit d6be17c

Please sign in to comment.