You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclose brought up the fact that fields aren't ordered in Add-Ons, which is something we have noted before and is a not ideal.
From my understanding, the front-end loads the JSON parameters that are pulled from addons/models.py from the originating config.yaml file for the Add-On.
Currently in our addons/models.py and in our python-documentcloud library we use the standard pyyaml (import yaml).
The YAML spec doesn't traditionally support ordering- but it also doesn't prohibit it. It gets loaded into a dict, which before Python 3.7, was unordered. Python >= 3.7, dicts maintain order.
For a sanity check, I even tested safe_load on PII detector's config.yaml file locally and confirmed that order, even within properties, was preserved:
I think the issue here is JSON not maintaining order in parameters
parameters = models.JSONField( ("parameters"),
default=dict,
help_text=("The user supplied parameters to run the add-on with"),
)
Is there some other way we could preserve order?
The text was updated successfully, but these errors were encountered:
I think the best way to preserve order is to add a list which specifies field order - this is guaranteed to be ordered by JSON, unlike object properties, which by spec have no order, despite some implementations possibly preserving order under some conditions. Previously we used a library which did not support specifying filed order (it is not part of JSON Schema), but Chris replaced it with his own form rendering library, so adding this should be fairly easy.
Disclose brought up the fact that fields aren't ordered in Add-Ons, which is something we have noted before and is a not ideal.
From my understanding, the front-end loads the JSON parameters that are pulled from addons/models.py from the originating config.yaml file for the Add-On.
Currently in our addons/models.py and in our python-documentcloud library we use the standard pyyaml (import yaml).
The YAML spec doesn't traditionally support ordering- but it also doesn't prohibit it. It gets loaded into a dict, which before Python 3.7, was unordered. Python >= 3.7, dicts maintain order.
In Python 3.7+, the dict we get from running yaml.safe_load returns a dictionary with order preserved.
https://medium.com/@reorx/tips-that-may-save-you-from-the-hell-of-pyyaml-572cde7e1d6f
This is also noted in this discussion on PyYaml's official issues here:
yaml/pyyaml#110 (comment)
For a sanity check, I even tested safe_load on PII detector's config.yaml file locally and confirmed that order, even within properties, was preserved:
I think the issue here is JSON not maintaining order in parameters
parameters = models.JSONField(
("parameters"),
default=dict,
help_text=("The user supplied parameters to run the add-on with"),
)
Is there some other way we could preserve order?
The text was updated successfully, but these errors were encountered: