Skip to content

[Suggestion] Why is the input value field so permissive? #164

@liamhuber

Description

@liamhuber

The input node value field is typed to be literally anything, but my abstract understanding is that it ought to be some sort of "primitive" data. Concretely, the current implementation does not have the juice to support the arbitrary type:

import numpy as np
from python_workflow_definition import models

inp_model = models.PythonWorkflowDefinitionInputNode.model_validate(
    {
        "id": 0,
        "type": "input",
        "name": "x",
        # "value": 1,  # Case 1
        # "value": (1, 2),  # Case 2
        # "value": np.arange(5)  # Case 3
    }
)
print(inp_model.model_dump_json(indent=2))

def cycle(model: models.PythonWorkflowDefinitionInputNode) -> bool:
    reloaded = type(model).model_validate(
        model.model_dump(mode="json"),
    )
    return model == reloaded

cycle(inp_model)
  • Case 1: Totally fine
  • Case 2: Dumps to something pretty reasonable, but doesn't cycle
  • Case 3: Won't validate because the data is not serializable

Is the typing here simply too permissive, or have I misunderstood the intent? If the latter, is there some plan for how to technically support non-primitive data?

TBH, I'm not exactly sure what I mean by primitive, but I guess something in this direction:

from typing import Union

JsonPrimitive = Union[str, int, float, bool, None]
JsonValue = Union[JsonPrimitive, list["JsonValue"], dict[str, "JsonValue"]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions