Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimvueConfiguration Pydantic fails when creating client #625

Open
timothy-nunn opened this issue Dec 10, 2024 · 1 comment · Fixed by #663
Open

SimvueConfiguration Pydantic fails when creating client #625

timothy-nunn opened this issue Dec 10, 2024 · 1 comment · Fixed by #663
Assignees
Labels
bug Something isn't working
Milestone

Comments

@timothy-nunn
Copy link

timothy-nunn commented Dec 10, 2024

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.

@timothy-nunn timothy-nunn changed the title SimvueConfiguration Pydantic SimvueConfiguration Pydantic fails when creating client Dec 10, 2024
@timothy-nunn
Copy link
Author

timothy-nunn commented Dec 10, 2024

Fixed with

[server]
url = "https://test.simvue.io"
token = "mytoken"

[run]
mode = "online"

however, this is a work around I believe because only the [server] config is provided by the SImvue website.

@kzscisoft kzscisoft added this to the Python API v2 milestone Jan 20, 2025
@kzscisoft kzscisoft linked a pull request Jan 21, 2025 that will close this issue
4 tasks
@kzscisoft kzscisoft added the bug Something isn't working label Jan 21, 2025
@kzscisoft kzscisoft self-assigned this Jan 21, 2025
@kzscisoft kzscisoft reopened this Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants