Skip to content

Commit 8bcd8c0

Browse files
committed
Updated 'TIFFPreprocessingResult' Pydantic model to parse stringified list
1 parent fbc9fe5 commit 8bcd8c0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/murfey/util/models.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

3+
from ast import literal_eval
34
from datetime import datetime
45
from pathlib import Path
56
from typing import Any, Dict, List, Optional
67

7-
from pydantic import BaseModel
8+
from pydantic import BaseModel, validator
89

910
"""
1011
General Models
@@ -175,7 +176,23 @@ class TIFFPreprocessingResult(BaseModel):
175176
series_name: str
176177
channel: str
177178
number_of_members: int
178-
parent_tiffs: List[Path]
179+
parent_tiffs: list[Path]
180+
181+
@validator(
182+
"parent_tiffs",
183+
pre=True,
184+
)
185+
def parse_stringified_list(cls, value):
186+
if isinstance(value, str):
187+
try:
188+
eval_result = literal_eval(value)
189+
if isinstance(eval_result, list):
190+
parent_tiffs = [Path(p) for p in eval_result]
191+
return parent_tiffs
192+
except (SyntaxError, ValueError):
193+
raise ValueError("Unable to parse input")
194+
# Return value as-is; if it fails, it fails
195+
return value
179196

180197

181198
"""

0 commit comments

Comments
 (0)