Skip to content

Commit

Permalink
fix: str list type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-v4s committed Sep 6, 2024
1 parent 62e1a72 commit 4f0aa37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions qualibrate_runner/api/routes/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
run_workflow,
validate_input_parameters,
)
from qualibrate_runner.core.types_parsing import types_conversion

submit_router = APIRouter(prefix="/submit")

Expand All @@ -43,10 +44,13 @@ def submit_node_run(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Already running",
)
converted_parameters = types_conversion(
input_parameters, node.parameters_class.serialize()
)
validate_input_parameters(
cast(Type[BaseModel], node.parameters_class), input_parameters
cast(Type[BaseModel], node.parameters_class), converted_parameters
)
background_tasks.add_task(run_node, node, input_parameters, state)
background_tasks.add_task(run_node, node, converted_parameters, state)
return f"Node job {node.name} is submitted"


Expand Down
6 changes: 1 addition & 5 deletions qualibrate_runner/core/run_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from qualibrate_runner.config import State
from qualibrate_runner.core.models.last_run import LastRun, RunError, RunStatus
from qualibrate_runner.core.types_parsing import types_conversion


def validate_input_parameters(
Expand Down Expand Up @@ -47,11 +46,8 @@ def run_node(
try:
library = get_active_library_or_error()
node = library.nodes[node.name]
converted_parameters = types_conversion(
passed_input_parameters, node.parameters_class.serialize()
)
result = library.run_node(
node.name, node.parameters_class(**converted_parameters)
node.name, node.parameters_class(**passed_input_parameters)
)
except Exception as ex:
state.last_run = LastRun(
Expand Down
9 changes: 9 additions & 0 deletions qualibrate_runner/core/types_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ def parse_float(value: VALUE_TYPES_WITHOUT_REC) -> VALUE_TYPES_WITHOUT_REC:


def parse_str(value: VALUE_TYPES_WITHOUT_REC) -> VALUE_TYPES_WITHOUT_REC:
if (
isinstance(value, str)
and len(value) > 1
and (
(value.startswith('"') and value.endswith('"'))
or (value.startswith("'") and value.endswith("'"))
)
):
return value[1:-1]
return value


Expand Down

0 comments on commit 4f0aa37

Please sign in to comment.