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

Aberta
#204 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
api

Direção de pesquisa

Comece em activeresource.py, na classe Errors e em seu método from_hash, e depois inspecione como as chaves de erro aninhadas são desempacotadas. Reproduza o caso metafield-on-variant usando a resposta metafields.namespace mostrada. Está concluído quando o erro retornado preserva a chave subject em vez de perder o campo que causa o erro.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

feature request

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

Linguagem predominante
Python
Estrelas
1.4k
Forks
388
Merge médio
5h 39min
PRs com merge (30d)
1

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de Shopify/shopify_python_api

Todas as issues de Shopify/shopify_python_api

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.