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

add validation for branch merge #4767

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Conversation

ajtmccarty
Copy link
Contributor

@ajtmccarty ajtmccarty commented Oct 29, 2024

fixes #4595
IFC-767

adds validation to the BranchMerge mutation to prevent merging a branch with constraint violations or diff conflicts

  • also fixes a couple of bugs in the new merge logic and adds some unit tests for them

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Oct 29, 2024
Copy link

codspeed-hq bot commented Oct 29, 2024

CodSpeed Performance Report

Merging #4767 will degrade performances by 24.25%

Comparing ajtm-10282024-validate-merge (7fa712e) with release-1.0 (3b5b366)

Summary

❌ 1 (👁 1) regressions
✅ 9 untouched benchmarks

Benchmarks breakdown

Benchmark release-1.0 ajtm-10282024-validate-merge Change
👁 test_schemabranch_duplicate 308.9 µs 407.8 µs -24.25%

Base automatically changed from ajtm-10182024-validate-rebase-merge-IFC-767 to release-1.0 October 29, 2024 13:48
registry.schema.set_schema_branch(name=obj.name, schema=updated_schema)
obj.update_schema_hash()
await obj.save(db=service.database)
async with lock.registry.global_graph_lock():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moving this all inside of a global graph lock

and conflict.selected_branch is ConflictSelection.DIFF_BRANCH
and conflict.base_branch_value
and conflict.base_branch_action in (DiffAction.ADDED, DiffAction.UPDATED)
):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if there is a conflict and the diff version is selected, we need to delete the version on main, which we were not doing before

def get_all_conflicts(self) -> list[EnrichedDiffConflict]:
return [prop.conflict for prop in self.properties if prop.conflict]
def get_all_conflicts(self) -> dict[str, EnrichedDiffConflict]:
return {prop.path_identifier: prop.conflict for prop in self.properties if prop.conflict}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updates to return a map of path identifier to EnrichedDiffConflict

@@ -390,7 +390,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
WHERE type(r_prop) = prop_type
AND r_prop.status = prop_rel_status
AND r_prop.from <= $at
AND (r_prop.to >= $at OR r_prop.to IS NULL)
AND (r_prop.to > $at OR r_prop.to IS NULL)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this off-by-one time error was causing a bug where the merge would delete an edge that it had just updated because the to time was set to $at

@@ -226,50 +229,32 @@ async def validate_graph(self) -> list[DataConflict]:
async def merge(
self,
at: Optional[Union[str, Timestamp]] = None,
conflict_resolution: Optional[dict[str, bool]] = None,
conflict_resolution: Optional[dict[str, bool]] = None, # pylint: disable=unused-argument
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will completely remove conflict_resolution in my next PR or 2

@@ -96,3 +87,161 @@ async def test_diff_and_merge_schema_with_default_values(
assert new_bool_attr.default_value is False
new_str_attr = car_schema_main.get_attribute(name="nickname")
assert new_str_attr.default_value == "car"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a few new tests to make sure that the merge is correctly handling resolved conflicts

@ajtmccarty ajtmccarty marked this pull request as ready for review October 30, 2024 01:10
@ajtmccarty ajtmccarty requested a review from a team October 30, 2024 01:10
@dgarros dgarros merged commit 638df73 into release-1.0 Oct 30, 2024
31 checks passed
@dgarros dgarros deleted the ajtm-10282024-validate-merge branch October 30, 2024 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants