Shopify / Shopify/shopify_python_api
Returned error in result missing error subject (discovered in metafield create/update)
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 1.4k
- 派生
- 388
- 平均合并
- 5 小时 39 分钟
- 30 天内合并 PR
- 1
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 activeresource.py 中的 Errors 类及其 from_hash 方法开始,然后检查嵌套错误键是如何展开的。使用所示的 metafields.namespace 响应重现 metafield-on-variant 情况。当返回的错误保留 subject 键,而不是丢失导致错误的字段时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100