diff --git a/antarest/study/storage/variantstudy/model/model.py b/antarest/study/storage/variantstudy/model/model.py index 1e51032ce4..3d881f6429 100644 --- a/antarest/study/storage/variantstudy/model/model.py +++ b/antarest/study/storage/variantstudy/model/model.py @@ -1,4 +1,4 @@ -from typing import List, Optional, Tuple, Union +from typing import List, NamedTuple, Optional, Tuple, Union from pydantic import BaseModel @@ -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() diff --git a/tests/integration/variant_blueprint/test_variant_manager.py b/tests/integration/variant_blueprint/test_variant_manager.py index 5af256dbbe..bdd2a02009 100644 --- a/tests/integration/variant_blueprint/test_variant_manager.py +++ b/tests/integration/variant_blueprint/test_variant_manager.py @@ -1,4 +1,6 @@ import logging +import random +import string from starlette.testclient import TestClient @@ -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