Shopify / Shopify/shopify_python_api

Returned error in result missing error subject (discovered in metafield create/update)

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

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

feature request
Ngôn ngữ chính
Python
Star
1.4k
Fork
388
Merge trung bình
5 giờ 39 phút
Pull request đã merge (30 ngày)
1

Mô tả

The shopify API returns the subject of an error as a key in the json error string, and pyactiveresource sometimes adds the value but not the key when it unpacks the string.

This probably shows up for some errors generated when adding or modifying variants or metafields, as they show up as lists of hashes in the object attributes. I hit a problem when adding or updating a metafield on a variant, and decided to dig.

The issue is in class Errors in activeresource.py:

    def from_hash(self, messages):
        attribute_keys = self.base.attributes.keys()
        for key, errors in six.iteritems(messages):
            for message in errors:
                if key in attribute_keys:
                    self.add(key, message)
                else:
                    self.add_to_base(message)

An error return like this:

{
    "errors": {
        "metafields.namespace": ["can't be blank", "is too short (minimum is 3 characters)"]
    }
}

(caused by trying to create or update a metafield with the key "name-space" instead of "namespace" :) will lose the important tidbit, the field causing the issue: "metafields" is a key in the variant attributes, but "metafields.namespace" is not.

Perhaps this might be a more robust approach?

    def from_hash(self, messages):
        attribute_keys = self.base.attributes.keys()
        for key, errors in six.iteritems(messages):
            for message in errors:
                if key.split('.')[0] in attribute_keys:
                    self.add(key, message)
                else:
                    self.add_to_base(' '.join([key, message]))

Thanks!

Rick

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu trong activeresource.py, tại class Errors và phương thức from_hash của nó, sau đó kiểm tra cách các khóa lỗi lồng nhau được giải nén. Tái hiện trường hợp metafield-on-variant bằng response metafields.namespace được hiển thị. Hoàn thành khi lỗi được trả về vẫn giữ khóa subject thay vì làm mất trường gây ra lỗi.

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

Đánh giá

Công nghệ
python
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

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.