JSONField for TestCase.metadata?
Since version 3.1 Django supports JSON fields:
https://docs.djangoproject.com/en/3.1/ref/models/fields/#jsonfield
This field allows database to keep JSON objects as a separate type.
For example, currently the JobErrorsView
relies on matching the string in the YAML string.
This is very slow to filter and is unreliable if for example the formatting changes.
Using the JSON field the lookups will be extremely fast and an index even possible.
You might ask ...but isn't metadata kept in YAML
. However, did you know that valid JSON object is a valid YAML?
import yaml
import json
yaml.safe_load(json.dumps({'a': 1, 'b': 'c'}))
# {'a': 1, 'b': 'c'}
So metadata can be kept as JSON but be served as YAML. Since only safe YAML is currently used there should not be any issues with primitive types.
Because Debian 11 only ships Django 2.2 this change will have to wait until Debian 11 support gets dropped.