-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
There was a problem hiding this 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
self, | ||
resource: CompiledNode, | ||
current_change_set: Optional[ChangeSet] = None, |
There was a problem hiding this comment.
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", "") |
There was a problem hiding this comment.
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!
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) |
There was a problem hiding this comment.
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, ✅
There was a problem hiding this 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 ✅ 🚀
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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may close #191
this is a tricky one!
update_child_refs()
to updatedepends_on
fields for exposures to take a two-arg ref if downstream of a model being split - worked well!ls
function until 1.7+ -- we need this for a variety of operations, so i updateddbt-core
for this package to1.7.4
dbt ls -s +orders
includes the semantic models attached to orders which means thatdbt-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!