Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code to properly handle reference deprecations #10852

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,25 +1315,6 @@ def singular_test_lookup(self) -> SingularTestLookup:
def external_node_unique_ids(self):
return [node.unique_id for node in self.nodes.values() if node.is_external_node]

def resolve_refs(
self,
source_node: ModelNode,
current_project: str, # TODO: ModelNode is overly restrictive typing
) -> List[MaybeNonSource]:
resolved_refs: List[MaybeNonSource] = []
for ref in source_node.refs:
resolved = self.resolve_ref(
source_node,
ref.name,
ref.package,
ref.version,
current_project,
source_node.package_name,
)
resolved_refs.append(resolved)

return resolved_refs

# Called by dbt.parser.manifest._process_refs & ManifestLoader.check_for_model_deprecations
def resolve_ref(
self,
Expand Down
55 changes: 28 additions & 27 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,35 +574,36 @@

def check_for_model_deprecations(self):
for node in self.manifest.nodes.values():
if isinstance(node, ModelNode) and node.is_past_deprecation_date:
warn_or_error(
DeprecatedModel(
model_name=node.name,
model_version=version_to_str(node.version),
deprecation_date=node.deprecation_date.isoformat(),
if isinstance(node, ModelNode) and node.deprecation_date:
if node.is_past_deprecation_date:
warn_or_error(

Check warning on line 579 in core/dbt/parser/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/manifest.py#L578-L579

Added lines #L578 - L579 were not covered by tests
DeprecatedModel(
model_name=node.name,
model_version=version_to_str(node.version),
deprecation_date=node.deprecation_date.isoformat(),
)
)
)

resolved_refs = self.manifest.resolve_refs(node, self.root_project.project_name)
resolved_model_refs = [r for r in resolved_refs if isinstance(r, ModelNode)]
node.depends_on
for resolved_ref in resolved_model_refs:
if resolved_ref.deprecation_date:
if resolved_ref.is_past_deprecation_date:
event_cls = DeprecatedReference
else:
event_cls = UpcomingReferenceDeprecation

warn_or_error(
event_cls(
model_name=node.name,
ref_model_package=resolved_ref.package_name,
ref_model_name=resolved_ref.name,
ref_model_version=version_to_str(resolved_ref.version),
ref_model_latest_version=str(resolved_ref.latest_version),
ref_model_deprecation_date=resolved_ref.deprecation_date.isoformat(),
)
# At this point _process_refs should already have been called, and
# the parent and child maps rebuilt.
# Get the child_nodes and check for deprecations.
child_nodes = self.child_map[node.unique_id]
for child_unique_id in child_nodes:
child_node = self.nodes[child_unique_id]
if node.is_past_deprecation_date:
event_cls = DeprecatedReference

Check warning on line 593 in core/dbt/parser/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/manifest.py#L589-L593

Added lines #L589 - L593 were not covered by tests
else:
event_cls = UpcomingReferenceDeprecation

Check warning on line 595 in core/dbt/parser/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/manifest.py#L595

Added line #L595 was not covered by tests

warn_or_error(

Check warning on line 597 in core/dbt/parser/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/manifest.py#L597

Added line #L597 was not covered by tests
event_cls(
model_name=child_node.name,
ref_model_package=node.package_name,
ref_model_name=node.name,
ref_model_version=version_to_str(node.version),
ref_model_latest_version=str(node.latest_version),
ref_model_deprecation_date=node.deprecation_date.isoformat(),
)
)

def check_for_spaces_in_resource_names(self):
"""Validates that resource names do not contain spaces
Expand Down
Loading