Skip to content

Commit 7decfe1

Browse files
committed
fix: improve api_constraints handling to support both string and parsed JSON
- Remove TODO comment and workaround for single input limitation - Add robust JSON parsing with error handling for malformed data - Support both string (JSON-encoded) and already-parsed constraints - Only extract data_type when constraint is a valid dict with the field - Resolves #214
1 parent b695e23 commit 7decfe1

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/routers/openml/tasktype.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,20 @@ def get_task_type(
6767
if task_type_input.requirement == "required":
6868
input_["requirement"] = task_type_input.requirement
6969
input_["name"] = task_type_input.name
70-
# api_constraints is for one input only in the test database (TODO: patch db)
71-
if isinstance(task_type_input.api_constraints, str):
72-
constraint = json.loads(task_type_input.api_constraints)
73-
input_["data_type"] = constraint["data_type"]
70+
# Parse api_constraints if present (handles both string and already-parsed JSON)
71+
if task_type_input.api_constraints:
72+
if isinstance(task_type_input.api_constraints, str):
73+
try:
74+
constraint = json.loads(task_type_input.api_constraints)
75+
except json.JSONDecodeError:
76+
# If JSON parsing fails, skip constraint (database may have malformed data)
77+
constraint = None
78+
else:
79+
# Already parsed as dict/list
80+
constraint = task_type_input.api_constraints
81+
82+
if constraint and isinstance(constraint, dict) and "data_type" in constraint:
83+
input_["data_type"] = constraint["data_type"]
7484
input_types.append(input_)
7585
task_type["input"] = input_types
7686
return {"task_type": task_type}

0 commit comments

Comments
 (0)