Skip to content

Commit f604330

Browse files
committed
PR feedback: remove DBT_ALL_MODEL_ATTRS placeholder
1 parent 1da06a3 commit f604330

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

sqlmesh/dbt/basemodel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
column_types_to_sqlmesh,
2020
)
2121
from sqlmesh.dbt.common import (
22-
DBT_ALL_MODEL_ATTRS,
2322
DbtConfig,
2423
Dependencies,
2524
GeneralConfig,
@@ -379,11 +378,11 @@ def _model_jinja_context(
379378
) -> t.Dict[str, t.Any]:
380379
if context._manifest and self.node_name in context._manifest._manifest.nodes:
381380
attributes = context._manifest._manifest.nodes[self.node_name].to_dict()
382-
if DBT_ALL_MODEL_ATTRS in dependencies.model_attrs:
381+
if dependencies.model_attrs.all_attrs:
383382
model_node: AttributeDict[str, t.Any] = AttributeDict(attributes)
384383
else:
385384
model_node = AttributeDict(
386-
filter(lambda kv: kv[0] in dependencies.model_attrs, attributes.items())
385+
filter(lambda kv: kv[0] in dependencies.model_attrs.attrs, attributes.items())
387386
)
388387

389388
raw_code_key = "raw_code" if DBT_VERSION >= (1, 3, 0) else "raw_sql" # type: ignore

sqlmesh/dbt/common.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import re
44
import typing as t
5+
from dataclasses import dataclass
56
from pathlib import Path
67

78
from ruamel.yaml.constructor import DuplicateKeyError
@@ -19,7 +20,6 @@
1920
T = t.TypeVar("T", bound="GeneralConfig")
2021

2122
PROJECT_FILENAME = DBT_PROJECT_FILENAME
22-
DBT_ALL_MODEL_ATTRS = "__DBT_ALL_MODEL_ATTRS__"
2323

2424
JINJA_ONLY = {
2525
"adapter",
@@ -173,6 +173,12 @@ def sqlmesh_config_fields(self) -> t.Set[str]:
173173
return set()
174174

175175

176+
@dataclass
177+
class ModelAttrs:
178+
attrs: t.Set[str]
179+
all_attrs: bool = False
180+
181+
176182
class Dependencies(PydanticModel):
177183
"""
178184
DBT dependencies for a model, macro, etc.
@@ -187,7 +193,7 @@ class Dependencies(PydanticModel):
187193
sources: t.Set[str] = set()
188194
refs: t.Set[str] = set()
189195
variables: t.Set[str] = set()
190-
model_attrs: t.Set[str] = set()
196+
model_attrs: ModelAttrs = ModelAttrs(attrs=set())
191197

192198
has_dynamic_var_names: bool = False
193199

@@ -197,7 +203,10 @@ def union(self, other: Dependencies) -> Dependencies:
197203
sources=self.sources | other.sources,
198204
refs=self.refs | other.refs,
199205
variables=self.variables | other.variables,
200-
model_attrs=self.model_attrs | other.model_attrs,
206+
model_attrs=ModelAttrs(
207+
attrs=self.model_attrs.attrs | other.model_attrs.attrs,
208+
all_attrs=self.model_attrs.all_attrs or other.model_attrs.all_attrs,
209+
),
201210
has_dynamic_var_names=self.has_dynamic_var_names or other.has_dynamic_var_names,
202211
)
203212

sqlmesh/dbt/manifest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from sqlmesh.utils.errors import SQLMeshError
4646
from sqlmesh.core.config import ModelDefaultsConfig
4747
from sqlmesh.dbt.builtin import BUILTIN_FILTERS, BUILTIN_GLOBALS, OVERRIDDEN_MACROS
48-
from sqlmesh.dbt.common import DBT_ALL_MODEL_ATTRS, Dependencies
48+
from sqlmesh.dbt.common import Dependencies
4949
from sqlmesh.dbt.model import ModelConfig
5050
from sqlmesh.dbt.package import HookConfig, MacroConfig
5151
from sqlmesh.dbt.seed import SeedConfig
@@ -584,7 +584,7 @@ def _extra_dependencies(
584584

585585
if isinstance(node, jinja2.nodes.Getattr):
586586
if call_name[0] == "model":
587-
dependencies.model_attrs.add(call_name[1])
587+
dependencies.model_attrs.attrs.add(call_name[1])
588588
elif call_name[0] == "source":
589589
args = [jinja_call_arg_name(arg) for arg in node.args]
590590
if args and all(arg for arg in args):
@@ -634,7 +634,7 @@ def _extra_dependencies(
634634
# analysis. We conservatively deal with this by including all of its supported attributes
635635
# if a standalone reference is found.
636636
if all_model_attrs:
637-
dependencies.model_attrs = {DBT_ALL_MODEL_ATTRS}
637+
dependencies.model_attrs.all_attrs = True
638638

639639
return dependencies
640640

tests/dbt/test_manifest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from sqlmesh.core.config import ModelDefaultsConfig
88
from sqlmesh.dbt.basemodel import Dependencies
9+
from sqlmesh.dbt.common import ModelAttrs
910
from sqlmesh.dbt.context import DbtContext
1011
from sqlmesh.dbt.manifest import ManifestHelper, _convert_jinja_test_to_macro
1112
from sqlmesh.dbt.profile import Profile
@@ -33,7 +34,7 @@ def test_manifest_helper(caplog):
3334
assert models["top_waiters"].dependencies == Dependencies(
3435
refs={"sushi.waiter_revenue_by_day", "waiter_revenue_by_day"},
3536
variables={"top_waiters:revenue", "top_waiters:limit"},
36-
model_attrs={"columns", "config"},
37+
model_attrs=ModelAttrs(attrs={"columns", "config"}),
3738
macros=[
3839
MacroReference(name="get_top_waiters_limit"),
3940
MacroReference(name="ref"),

0 commit comments

Comments
 (0)