Ordered fields for Add-Ons

Đang mở
#185 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Python
Star
55
Fork
10
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MuckRock/documentcloud

Tất cả issue của MuckRock/documentcloud

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.