Skip to content

Commit

Permalink
Handle disabled SavedQuery nodes in parsing and lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Oct 10, 2023
1 parent 0e94d4d commit d64ab57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
19 changes: 15 additions & 4 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ class Disabled(Generic[D]):
MaybeMetricNode = Optional[Union[Metric, Disabled[Metric]]]


MaybeSavedQueryNode = Optional[Union[SavedQuery, Disabled[SavedQuery]]]


MaybeDocumentation = Optional[Documentation]


Expand Down Expand Up @@ -1208,19 +1211,27 @@ def resolve_saved_query(
target_saved_query_package: Optional[str],
current_project: str,
node_package: str,
) -> Optional[SavedQuery]:
) -> MaybeSavedQueryNode:
"""Tries to find the SavedQuery by name within the available project and packages.
Will return the first SavedQuery matching the name found while iterating over the
scoped packages. Returns `None` if no match is found.
Will return the first enabled SavedQuery matching the name found while iterating over
the scoped packages. If no enabled SavedQuery node match is found, returns the last
disabled SavedQuery node. Otherwise it returns None.
"""
disabled: Optional[List[SavedQuery]] = None
candidates = _packages_to_search(current_project, node_package, target_saved_query_package)
for pkg in candidates:
saved_query = self.saved_query_lookup.find(target_saved_query_name, pkg, self)

if saved_query is not None:
if saved_query is not None and saved_query.config.enabled:
return saved_query

# it's possible that the node is disabled
if disabled is None:
disabled = self.disabled_lookup.find(f"{target_saved_query_name}", pkg)
if disabled:
return Disabled(disabled[0])

return None

def resolve_semantic_model_for_measure(
Expand Down
6 changes: 5 additions & 1 deletion core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,11 @@ def parse_saved_query(self, unparsed: UnparsedSavedQuery) -> None:
unrendered_config=unrendered_config,
)

self.manifest.add_saved_query(self.yaml.file, parsed)
# Only add thes saved query if it's enabled, otherwise we track it with other diabled nodes
if parsed.config.enabled:
self.manifest.add_saved_query(self.yaml.file, parsed)
else:
self.manifest.add_disabled(self.yaml.file, parsed)

def parse(self) -> ParseResult:
for data in self.get_key_dicts():
Expand Down

0 comments on commit d64ab57

Please sign in to comment.