Skip to content

Commit d6c7d98

Browse files
authored
Fix: Extraction of variables that belong to the target package (#1012)
1 parent 4786f58 commit d6c7d98

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

sqlmesh/dbt/context.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ def _var(name: str, default: t.Optional[t.Any] = None) -> t.Any:
107107

108108
jinja_environment.globals["var"] = _var
109109

110-
rendered_variables = {k: _render_var(v) for k, v in variables.items()}
110+
rendered_variables = {}
111+
for k, v in variables.items():
112+
try:
113+
rendered_variables[k] = _render_var(v)
114+
except Exception as ex:
115+
raise ConfigError(f"Failed to render variable '{k}', value '{v}': {ex}") from ex
116+
111117
self.variables = rendered_variables
112118

113119
@property

sqlmesh/dbt/package.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ def load(self, package_root: Path) -> Package:
7070

7171
# Only include globally-scoped variables (i.e. filter out the package-scoped ones)
7272
logger.debug("Processing project variables.")
73-
variables = {
74-
var: value
75-
for var, value in project_yaml.get("vars", {}).items()
76-
if not isinstance(value, dict)
73+
74+
all_variables = project_yaml.get("vars", {})
75+
all_variables.update(all_variables.pop(package_name, {}))
76+
77+
package_variables = {
78+
var: value for var, value in all_variables.items() if not isinstance(value, dict)
7779
}
7880

7981
tests = _fix_paths(self._context.manifest.tests(package_name), package_root)
@@ -96,7 +98,7 @@ def load(self, package_root: Path) -> Package:
9698
models=models,
9799
sources=sources,
98100
seeds=seeds,
99-
variables=variables,
101+
variables=package_variables,
100102
macros=macros,
101103
files=config_paths,
102104
)

0 commit comments

Comments
 (0)