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

Children of multiple boundary nodes #148

Merged
merged 6 commits into from
Aug 25, 2023

Conversation

dave-connors-3
Copy link
Collaborator

Resolves #147

This PR adds some state awareness to the split and connect commands so that updates to ref functions are additive and not destructive!

When splitting:

  1. if updating child refs, check the current list of changes for any already existing code changes to the target resource at the sql path. Use the data from that change instead of the raw code if there's a previous one
  2. if updating the parent refs, use the code from the last update to the current resource. This iteration is happening on a per-child basis, so this function does not need the full list of current children

When connecting

  1. if updating child refs for package dependencies, check the current list of changes for any already existing code changes to the target resource at the sql path. Use the data from that change instead of the raw code if there's a previous one

I am not completely in love with the approach, so would relish some feedback

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 approach seems both necessary and sufficient. I left a suggestion to extract some shared functionality to keep the code DRY. Otherwise, looks good. Great sleuthing on this!

Comment on lines 147 to 168
if current_change_set:
previous_changes: List[FileChange] = [
change
for change in current_change_set.changes
if (
isinstance(change, FileChange)
and change.identifier == model_node.name
and change.operation == Operation.Update
and change.entity_type == EntityType.Code
and change.path
== self.project.parent_project.resolve_file_path(model_node)
)
]
previous_change = previous_changes[-1] if previous_changes else None

change = self.generate_reference_update(
project_name=self.project.name,
upstream_node=resource,
downstream_node=model_node,
code=model_node.raw_code,
code=previous_change.data
if (previous_change and previous_change.data)
else model_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 approach seems reasonable. Since this filtering is being done here and in linker.py, I think it might be appropriate to extract this logic into a function in this file (references.py) that both this method and the linker.py method can leverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

totally agree - would this be a method on the ReferenceUpdater Class, or just a function outside the scope of the class?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking outside the ReferenceUpdater class scope.

@nicholasyager nicholasyager added the bug Something isn't working label Aug 25, 2023
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 an excellent fix. Thanks for the updates. ✅

Comment on lines +324 to +336
if current_change_set:
previous_change = get_latest_file_change(
changeset=current_change_set,
identifier=downstream_manifest_entry.name,
path=downstream_project.resolve_file_path(downstream_manifest_entry),
)

code_to_update = (
previous_change.data
if (previous_change and previous_change.data)
else downstream_manifest_entry.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.

I really like how this flows! Thanks for making the change.

@dave-connors-3 dave-connors-3 merged commit 83bd564 into main Aug 25, 2023
@nicholasyager nicholasyager deleted the children-of-multiple-boundary-nodes branch September 1, 2023 12:53
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.

models with multiple cross project Parents are not properly updated
2 participants