Skip to content

Commit

Permalink
fix: fix a bug that would occurs after deleting multiple bc (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPascoli authored Jan 27, 2025
1 parent cbe394d commit f213a26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ def _apply(self, study_data: FileStudy, listener: t.Optional[ICommandListener] =
if binding_constraints[key].get("id") in self.ids:
deleted_binding_constraints.append(binding_constraints.pop(key))

# BC dict should start at index 0
new_binding_constraints = {str(i): value for i, value in enumerate(binding_constraints.values())}

study_data.tree.save(
binding_constraints,
new_binding_constraints,
["input", "bindingconstraints", "bindingconstraints"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,15 @@ def test_for_version_870(self, client: TestClient, user_access_token: str, study
assert res.status_code == 200, res.json()

# Asserts that the deletion worked
binding_constraints_list = preparer.get_binding_constraints(study_id)
binding_constraints_list = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": f"input/bindingconstraints/bindingconstraints"}, # type: ignore
).json()
assert len(binding_constraints_list) == 2
actual_ids = [constraint["id"] for constraint in binding_constraints_list]
actual_ids = [constraint["id"] for constraint in binding_constraints_list.values()]
assert actual_ids == ["binding_constraint_1", "binding_constraint_3"]
keys = sorted(int(k) for k in binding_constraints_list.keys())
assert keys == list(range(len(keys)))

# =============================
# CONSTRAINT DUPLICATION
Expand Down

0 comments on commit f213a26

Please sign in to comment.