Skip to content

Commit

Permalink
Fix #9534: Add NodeRelation to SavedQuery Export
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Apr 9, 2024
1 parent cf08b84 commit c40eaf9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(self, config: RuntimeConfig, manifest: Manifest, component: str) ->
self.component = component

def __call__(self, parsed_node: Any, override: Optional[str]) -> None:
if parsed_node.package_name in self.package_updaters:
if getattr(parsed_node, "package_name", None) in self.package_updaters:
new_value = self.package_updaters[parsed_node.package_name](override, parsed_node)
else:
new_value = self.default_updater(override, parsed_node)
Expand Down Expand Up @@ -293,7 +293,7 @@ def update_parsed_node_relation_names(
self._update_node_alias(parsed_node, config_dict.get("alias"))

# Snapshot nodes use special "target_database" and "target_schema" fields for some reason
if parsed_node.resource_type == NodeType.Snapshot:
if getattr(parsed_node, "resource_type", None) == NodeType.Snapshot:
if "target_database" in config_dict and config_dict["target_database"]:
parsed_node.database = config_dict["target_database"]
if "target_schema" in config_dict and config_dict["target_schema"]:
Expand Down Expand Up @@ -452,7 +452,7 @@ def _update_node_relation_name(self, node: ManifestNode):
# and TestNodes that store_failures.
# TestNodes do not get a relation_name without store failures
# because no schema is created.
if node.is_relational and not node.is_ephemeral_model:
if getattr(node, "is_relational", None) and not getattr(node, "is_ephemeral_model", None):
adapter = get_adapter(self.root_project)
relation_cls = adapter.Relation
node.relation_name = str(relation_cls.create_from(self.root_project, node))
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ def parse_saved_query(self, unparsed: UnparsedSavedQuery) -> None:
group=config.group,
)

for export in parsed.exports:
self.schema_parser.update_parsed_node_relation_names(export, export.config.to_dict()) # type: ignore

Check warning on line 768 in core/dbt/parser/schema_yaml_readers.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/schema_yaml_readers.py#L767-L768

Added lines #L767 - L768 were not covered by tests

# 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)
Expand Down

0 comments on commit c40eaf9

Please sign in to comment.