Skip to content

SimvueConfiguration Pydantic fails when creating client #625

@timothy-nunn

Description

@timothy-nunn

Running the following code on Simvue 1.1.3 produces a traceback:

from simvue.client import Client

client = Client()
(.venv) timothynunn@L0268-iMac eqm-ml % python test.py 
Traceback (most recent call last):
  File "/Users/timothynunn/eqm-ml/.venv/lib/python3.10/site-packages/simvue/utilities.py", line 251, in wrapper
    return class_func(self, *args, **kwargs)
  File "/Users/timothynunn/eqm-ml/.venv/lib/python3.10/site-packages/simvue/config/user.py", line 214, in fetch
    return SimvueConfiguration(**_config_dict)
  File "/Users/timothynunn/eqm-ml/.venv/lib/python3.10/site-packages/pydantic/main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for SimvueConfiguration
run.mode
  Input should be 'offline', 'disabled' or 'online' [type=literal_error]
    For further information visit https://errors.pydantic.dev/2.6/v/literal_error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/timothynunn/eqm-ml/test.py", line 3, in <module>
    client = Client()
  File "/Users/timothynunn/eqm-ml/.venv/lib/python3.10/site-packages/simvue/client.py", line 109, in __init__
    self._user_config = SimvueConfiguration.fetch(
  File "/Users/timothynunn/eqm-ml/.venv/lib/python3.10/site-packages/simvue/utilities.py", line 254, in wrapper
    raise RuntimeError(error_str)
RuntimeError: `fetch` Validation:
╒═════════╤═════════════════╤═══════════════╤═══════════════════════════════════════════════════╕
│ Input   │ Location        │ Type          │ Message                                           │
╞═════════╪═════════════════╪═══════════════╪═══════════════════════════════════════════════════╡
│ None    │ ['run', 'mode'] │ literal_error │ Input should be 'offline', 'disabled' or 'online' │
╘═════════╧═════════════════╧═══════════════╧═══════════════════════════════════════════════════╛

It appears that simvue.config.parameters.DefaultRunSpecifications is typed to only accept literal strings while simvue.config.user.SimvueConfiguration.fetch accepts mode as optional. Therefore, on line 202, _run_mode = mode or _config_dict["run"].get("mode") which equates to _run_mode = None or None. This None is passed to the DefaultRunSpecifications and fails the literal check.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions