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 4, 2024
1 parent c482184 commit 108e06e
Show file tree
Hide file tree
Showing 2 changed files with 18 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()
15 changes: 15 additions & 0 deletions tests/integration/variant_blueprint/test_variant_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import random
import string

from starlette.testclient import TestClient

Expand Down Expand Up @@ -186,3 +188,16 @@ def test_variant_manager(client: TestClient, admin_access_token: str, study_id:

res = client.get(f"/v1/studies/{variant_id}", headers=admin_headers)
assert res.status_code == 404


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 108e06e

Please sign in to comment.