Keep backward compatibility of widget definition

This commit is contained in:
c-bata
2023-02-10 10:58:48 +09:00
parent 93b188f20a
commit d98eaa6fb9
+8 -2
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import json
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import Union
@@ -109,7 +110,7 @@ class ObjectiveUserAttrRef:
ObjectiveFormWidget = Union[
ObjectiveChoiceWidget, ObjectiveSliderWidget, ObjectiveTextInputWidget, ObjectiveUserAttrRef
]
SYSTEM_ATTR_KEY = "dashboard:objective_form_widgets"
SYSTEM_ATTR_KEY = "dashboard:objective_form_widgets:v1"
def register_objective_form_widgets(
@@ -124,4 +125,9 @@ def register_objective_form_widgets(
def get_objective_form_widgets_json(
study_system_attr: dict[str, Any]
) -> Optional[list[ObjectiveFormWidgetJSON]]:
return study_system_attr.get(SYSTEM_ATTR_KEY)
if SYSTEM_ATTR_KEY in study_system_attr:
return study_system_attr[SYSTEM_ATTR_KEY]
# For optuna-dashboard v0.9.0b5 users
if "dashboard:objective_form_widgets" in study_system_attr:
return json.loads(study_system_attr["dashboard:objective_form_widgets"])
return None