Non-string attributes are allowed but not supported by schema #907
Labels
type:bug
Something isn't working
zone:backend
MWDB backend core related tasks
zone:frontend
MWDB frontend tasks
Milestone
Environment information
/about
): 2.10.3pip install mwdb-core
)Behaviour the bug (what happened?)
Attribute value should be a string, as defined in the schema:
mwdb-core/mwdb/schema/metakey.py
Lines 25 to 31 in ee5cb12
However, the introduction of the rich attributes feature opened the possibility for attributes that aren't strings. To do this, all we need to do is define a rich attribute template of the form
{{value}}
. Then we can put in thevalue
section of the attribute some non-string value, for example the number 8, and what will happen is that the object will have the integer value 8 as an attribute value. Not a string but a number. This can be verified by the query functionality, you can treat this attribute as a number in a query and use feature like number ranges for it. This also works for float, so a value of 5.76 works as expected when doing this trick.The problem here is that as seen in the schema, attribute values are expected to be strings and this can lead to weird behavior when using this trick. Let's say I define an attribute called
vt-detections
for samples, this is naturally an integer. And let's say I use this trick to make it treated like an integer. Then, when a sample comes in and it has 0 VT detections, it will fail the schema validation. Invalidate_value
we havevalue==0
thusnot value == True
and this results in a nice error message. Despite 0 being a legitimate value in this case.Expected behaviour
I think that instead of enforcing users not to use non-string values, this should be embraced and added as a system feature. I would do the following:
isinstance
. Have different validators for strings, integers, floats, and rich attributesAlso, maybe add to an each attribute its (user defined) type in the DB to prevent the user from having multiple different types. For example not to have some attribute sometimes as a string and sometimes as an integer, as this makes a difference in searching.
Reproduction Steps
{{value}}
0
The text was updated successfully, but these errors were encountered: