labthings / labthings/labthings-fastapi
ThingSettings are passed a dictionary not a BaseModel of the correct type when loading from JSON
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When saving everything is converted to JSON, if the type for a setting is a BaseModel it is serialised to a JSON. For all standard Python types they also convert easily to JSON via being put in a dictionary of settings.
On load the standard python types are loaded correctly, but the BaseModel is loaded as a dictionary. This means the setter for the ThingSetting is passed a Dictionary not a BaseModel of the correct type. This is currently handled in the OpenFlexure Microscope by explicitly using a setter for the anything that is a base model and type checking for dictionaries.
To Reproduce
Create a ThingSetting with a BaseModel as the type
Expected behaviour
The server should deserialise the data back into the correct type before sending to the setter.
System:
- OS: Ubuntu 24.04 and OpenFlexure Raspian
- Python version 3.11
- Version 0.0.10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by creating a ThingSetting whose type is a BaseModel, then trace the JSON loading path to the setter. Verify the current value is a dictionary and confirm that the completed fix passes an instance of the declared BaseModel type to the setter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100