Replies: 7 comments 3 replies
-
This should be done using pydantic. I think it should be possible to enforce errors for incorrect types in meta, although I can see this becoming a bit of a mess. |
Beta Was this translation helpful? Give feedback.
-
Type hints introduced in #53 should help a bit. Hints suggest values must be Line 27 in 7116ee0 |
Beta Was this translation helpful? Give feedback.
-
Defining an OpenAPI schema and then generating a pydantic model looks like the best approach: https://koxudaxi.github.io/datamodel-code-generator/ Then I can use similar tools on the gui side to generate schema for the front-end, which is important because it also deals with meta files! (Possibly should have full control). Finding the best way to integrate the pydantic model with the Meta implementation may be a challenge. |
Beta Was this translation helpful? Give feedback.
-
Adding model validate checks might work: https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_validate I don't think we want to be creating millions of instances of the model. The models are kinda designed to be wrappers around dictionaries... I guess I could make https://docs.pydantic.dev/latest/concepts/models/#faux-immutability Then for refreshing can dump: https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump_json |
Beta Was this translation helpful? Give feedback.
-
This maybe needs a little more thought... We are encouraging users to insert whatever they like into the meta, which will have all sorts of types. How do we assure those types? The hope was also that these types could be communicated to the front end for validation, how can this happen if they are dynamic? One option is to set up The only problem with that is that we have this slightly messy thing that things you might want to store in meta are not universal across all instances of the same tier. For example, some Samples might require temperature information, and others concentrations. |
Beta Was this translation helpful? Give feedback.
-
Ok I think here's the best way... So, it looks like models can generate schema of themselves: https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump_json And we can allow arbitrary attributes (I presume they must be json serialisable, otherwise dump won't work!) https://docs.pydantic.dev/latest/concepts/models/#extra-fields For 'core' attributes, we need to ensure they're consistent. I think the best way to do this is using the MetaAttr idea above i.e. generate some parts of the schema from that. This could be done during For 'extra' attributes, I am fairly sure Pydantic will make sure they're serialisable, which was the original concern. Then, at the server side for the front end, we can provide a schema using |
Beta Was this translation helpful? Give feedback.
-
The current, somewhat convoluted implementation involving the MetaManagers, which is frankly kinda confusing... anyway, one thing is that we pass I think this makes a lot more sense and makes it explicit that Meta of the same Tier Class should have the same model. This will be helpful for later when we want to serve up the models for meta. |
Beta Was this translation helpful? Give feedback.
-
If you insert non JSON data into a meta dict, everything freaks out because whenever meta tries to write to disk, it can't.
We should verify something is serialisable prior to insertion.
Beta Was this translation helpful? Give feedback.
All reactions