Skip to content

Commit 12b016b

Browse files
fix doc typo; add error handling
1 parent 04b162a commit 12b016b

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

docs/concepts/macros/macro_variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ The following variables are also available in [`before_all` and `after_all` stat
141141

142142
* @this_env - A string value containing the name of the current [environment](../environments.md).
143143
* @schemas - A list of the schema names of the [virtual layer](../../concepts/glossary.md#virtual-layer) of the current environment.
144-
* @views - A list of the views names of the [virtual layer](../../concepts/glossary.md#virtual-layer) of the current environment.
144+
* @views - A list of the view names of the [virtual layer](../../concepts/glossary.md#virtual-layer) of the current environment.

docs/guides/configuration.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,6 @@ For example, rather than using an `on_virtual_update` statement in each model to
10191019

10201020
```python linenums="1"
10211021
from sqlmesh.core.macros import macro
1022-
from sqlmesh.core.snapshot.definition import to_view_mapping
10231022
10241023
@macro()
10251024
def grant_select_privileges(evaluator):

sqlmesh/core/macros.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,19 +497,25 @@ def snapshots(self) -> t.Dict[str, Snapshot]:
497497
return self._snapshots
498498

499499
@property
500-
def this_env(self) -> t.Optional[str]:
500+
def this_env(self) -> str:
501501
"""Returns the name of the current environment in before after all."""
502-
return self.locals.get("this_env")
502+
if "this_env" not in self.locals:
503+
raise SQLMeshError("Environment name is not available in this context")
504+
return self.locals["this_env"]
503505

504506
@property
505-
def schemas(self) -> t.Optional[t.List[str]]:
507+
def schemas(self) -> t.List[str]:
506508
"""Returns the schemas of the current environment in before after all macros."""
507-
return self.locals.get("schemas")
509+
if "schemas" not in self.locals:
510+
raise SQLMeshError("Schemas are not available in this context")
511+
return self.locals["schemas"]
508512

509513
@property
510-
def views(self) -> t.Optional[t.List[str]]:
514+
def views(self) -> t.List[str]:
511515
"""Returns the views of the current environment in before after all macros."""
512-
return self.locals.get("views")
516+
if "views" not in self.locals:
517+
raise SQLMeshError("Views are not available in this context")
518+
return self.locals["views"]
513519

514520
def var(self, var_name: str, default: t.Optional[t.Any] = None) -> t.Optional[t.Any]:
515521
"""Returns the value of the specified variable, or the default value if it doesn't exist."""

0 commit comments

Comments
 (0)