Ordered fields for Add-Ons

未关闭
#185 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

Start by reading addons/models.py and tracing how Add-On config.yaml parameters are loaded and stored, including the python-documentcloud library path mentioned in the issue. Check whether ordering is lost during JSONField storage or later serialization; done means identifying a supported way to preserve field order through to the front end.

由索引模型根据 Issue 内容生成。

描述

addons enhancement

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:
https://github.com/yaml/pyyaml/issues/110#issuecomment-500882817

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:
Order 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?

主要语言
Python
星标
55
派生
10
平均合并
1 天 13 小时
30 天内合并 PR
22

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MuckRock/documentcloud 的其他 Issue

查看 MuckRock/documentcloud 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。