Skip to content

Commit

Permalink
fix(variants): don't raise Recursive error when creating big variant …
Browse files Browse the repository at this point in the history
…tree
  • Loading branch information
MartinBelthle committed Mar 6, 2024
1 parent f7f082a commit 9ef7df1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 3 additions & 5 deletions antarest/study/storage/variantstudy/model/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Tuple, Union
from typing import List, NamedTuple, Optional, Tuple, Union

from pydantic import BaseModel

Expand Down Expand Up @@ -26,9 +26,7 @@ class CommandResultDTO(BaseModel):
message: str


class VariantTreeDTO(BaseModel):
class VariantTreeDTO(NamedTuple):
# Don't use BaseModel as this could trigger Recursion exceptions, since we're using Pydantic with a version prior to v2.
node: StudyMetadataDTO
children: List["VariantTreeDTO"]


VariantTreeDTO.update_forward_refs()
13 changes: 13 additions & 0 deletions tests/integration/variant_blueprint/test_variant_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,16 @@ def test_comments(client: TestClient, admin_access_token: str, variant_id: str)
# Asserts comments did not disappear
res = client.get(f"/v1/studies/{variant_id}/comments", headers=admin_headers)
assert res.json() == comment


def test_recursive_variant_tree(client: TestClient, admin_access_token: str):
admin_headers = {"Authorization": f"Bearer {admin_access_token}"}
base_study_res = client.post("/v1/studies?name=foo", headers=admin_headers)
base_study_id = base_study_res.json()
parent_id = base_study_res.json()
for k in range(150):
res = client.post(f"/v1/studies/{base_study_id}/variants?name=variant_{k}", headers=admin_headers)
base_study_id = res.json()
# Asserts that we do not trigger a Recursive Exception
res = client.get(f"/v1/studies/{parent_id}/variants", headers=admin_headers)
assert res.status_code == 200

0 comments on commit 9ef7df1

Please sign in to comment.