Skip to content

Running step with parameter default None raises error #362

@leoyala

Description

@leoyala

Creating a valohai step and running it locally using python raises an error when the data type is meant to be anything that is not NoneType but the default value is None.
The following step can be used to test this.

"""Test Valohai step that prints an integer parameter with default value None."""

import valohai


def main() -> None:
    """Main execution function that prints the test parameter."""
    # Get the parameter value
    test_param = valohai.parameters("test_int_param").value

    # Print the parameter value and its type
    print(f"Parameter value: {test_param}")
    print(f"Parameter type: {type(test_param)}")
    print(f"Is None: {test_param is None}")


if __name__ == "__main__":
    default_parameters = {
        "test_int_param": {
            "type": "integer",
            "default": None,
            "optional": True,
            "description": "Test integer parameter with default value None.",
        },
    }

    valohai.prepare(
        step="test-int-none-param",
        image="python:3.12-slim",
        default_parameters=default_parameters,
    )
    main()

Run command:
python python valohai/test_int_none_param.py --test_int_param=1
Output:

usage: test_int_none_param.py [-h] [--test_int_param TEST_INT_PARAM]
test_int_none_param.py: error: argument --test_int_param: invalid NoneType value: '1'

Expected behavior:
The script should still run even when the default value is None as long as the parameter type matches the type specified in the step.

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