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

update refs in exposure and semantic model definitions when downstream of a split resource #194

Merged
merged 14 commits into from
Mar 13, 2024

Conversation

dave-connors-3
Copy link
Collaborator

@dave-connors-3 dave-connors-3 commented Jan 15, 2024

may close #191

this is a tricky one!

  1. Updated the logic in update_child_refs() to update depends_on fields for exposures to take a two-arg ref if downstream of a model being split - worked well!
  2. Wanted to extend the same logic to semantic models as well -- this is where we took a turn:
  • dbt-core did not add the ability to return semantic models in an ls function until 1.7+ -- we need this for a variety of operations, so i updated dbt-core for this package to 1.7.4
  • after updating, the logic in dbt ls -s +orders includes the semantic models attached to orders which means that dbt-meshify split test --select +orders moves the orders semantic model th##at I added to the new project. This is a) good that we do what dbt-core tells us to do but b) not at all the behavior that I expected. As such, I added a test that is just a pass until we can figure out what the expected behavior is.

update 1/16

the reason that the semantic model was being selected and moved was because the model and semantic model had the same name! so this was in fact selected as well. This is expected behavior, but is a bit of a stumbling block if trying to have a semantic model reference a newly split resource.

That said, i believe this is ready to be reviewed -- the string matching on refs is not my cleanest code so very open to suggestions!

@dave-connors-3 dave-connors-3 marked this pull request as ready for review January 16, 2024 18:36
@dave-connors-3 dave-connors-3 changed the title Exposures update refs in exposure and semantic model definitions when downstream of a split resource Jan 16, 2024
Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dave-connors-3 This is great! I had a couple of nitpicks in references.py around how one might simplify, but those are non-blocking IMHO. This change seems both necessary and sufficient

dbt_meshify/utilities/references.py Outdated Show resolved Hide resolved
dbt_meshify/utilities/references.py Outdated Show resolved Hide resolved
Comment on lines +212 to +214
self,
resource: CompiledNode,
current_change_set: Optional[ChangeSet] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray for improved formatting!

)
code = (
previous_change.data
if (previous_change and previous_change.data)
else model_node.raw_code
else getattr(node, "raw_code", "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such a better way of getting the code. Good thinking!

Comment on lines +157 to +164
for ref in refs:
package_clause = f"'{ref.package}', " if ref.package else ""
name_clause = f"'{ref.name}'"
version_clause = f", v={ref.version}" if ref.version else ""
str_ref = f"ref({package_clause}{name_clause}{version_clause})"
if str_ref != ref_to_update:
str_refs.append(str_ref)
str_refs.append(new_ref)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in believing that this code fully specifies each resource ref, and then adds the updated upstream source ref? If so, this seems sufficient. Perhaps it would be valuable to create a function that generates ref strings for resources? Either way, ✅

Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dave-connors-3 Thanks for making some formatting/simplification tweaks. This PR looks both necessary and sufficient ✅ 🚀

Comment on lines +193 to +207
elif isinstance(downstream_node, Exposure) or isinstance(downstream_node, SemanticModel):
is_exposure = isinstance(downstream_node, Exposure)
data = self.update_yml_resource_references(
project_name=project_name,
upstream_resource_name=upstream_node.name,
resource=downstream_node,
)
return ResourceChange(
operation=Operation.Update,
entity_type=EntityType.Exposure if is_exposure else EntityType.SemanticModel,
identifier=downstream_node.name,
path=downstream_project.resolve_file_path(downstream_node),
data=data,
)
raise Exception("Invalid node type provided to generate_reference_update.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic Doctor Who GIF

@dave-connors-3 dave-connors-3 merged commit 55eebc1 into main Mar 13, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

exposures do not play nice with meshify
2 participants