unevaluatedProperties error gets raised before more relevant validation errors
Mantenedores costumam responder em até 6 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- python
- Domínio
- backend-api-design
Direção de pesquisa
Reproduza o schema fornecido com jsonschema.validate e Draft202012Validator.validate e, em seguida, inspecione find_evaluated_property_keys_by_schema em jsonschema/_utils.py e a lógica de seleção de erros em jsonschema/exceptions.py. Compare os erros resultantes e determine como unevaluatedProperties deve evitar mascarar o erro de validação mais relevante do subschema; a tarefa estará concluída quando o exemplo relatar consistentemente a violação máxima.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Hello!
I noticed that in schemas using 'allOf' and unevaluatedProperties, when there is an error in a subschema, instead of showing the relevant error, unevaluatedProperties is (sometimes?) shown instead. This makes it really hard to see what went wrong in anything larger than trivial examples. This seems to be related to https://github.com/python-jsonschema/jsonschema/issues/1074, just with a different scenario.
Here is a small example:
import jsonschema
obj = {
"fridge_min_temp": 10
}
schema = {
"type": "object",
"allOf": [
{
"properties": {
"fridge_min_temp": { "type": "integer", "minimum": -20, "maximum": 5 }
},
"required": ["fridge_min_temp"]
}
],
"unevaluatedProperties": False
}
jsonschema.validate(obj, schema)
Which produces the error trace:
ValidationError: Unevaluated properties are not allowed ('fridge_min_temp' was unexpected)
Failed validating 'unevaluatedProperties' in schema:
{'allOf': [{'properties': {'fridge_min_temp': {'maximum': 5,
'minimum': -20,
...
'type': 'object',
'unevaluatedProperties': False}
On instance:
{'fridge_min_temp': 10}
If I validate instead using:
jsonschema.Draft202012Validator(schema).validate(obj)
Then the raised error is much more helpful:
ValidationError: 10 is greater than the maximum of 5
Failed validating 'maximum' in schema['allOf'][0]['properties']['fridge_min_temp']:
{'maximum': 5, 'minimum': -20, 'type': 'integer'}
On instance['fridge_min_temp']:
10
Seems like this happens because jsonschema.validate is equivalent to raise best_match(jsonschema.Draft202012Validator(schema).iter_errors(obj)) in this case, and the best_match heuristic downgrades any errors coming from 'allOf' and 'oneOf'.
With a more complex schema, I get an unevaluatedProperties error using both approaches.
3 ways of going about it could be:
-
The suggestion from https://github.com/python-jsonschema/jsonschema/issues/1074 to separately keep track of unevaluated properties and invalid properties, and write different error messages for them.
-
Add properties to evaluated keys even if there are errors resulting from
validator.descendin https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/_utils.py:
def find_evaluated_property_keys_by_schema(validator, instance, schema):
# ...
for keyword in ["allOf", "oneOf", "anyOf"]:
if keyword in schema:
for subschema in schema[keyword]:
errs = next(validator.descend(instance, subschema), None)
if errs is None:
evaluated_keys += find_evaluated_property_keys_by_schema(
validator, instance, subschema,
)
This way unevaluatedProperties will not get raised for properties with subschema errors at all (which shouldn't be a problem, because it'll get raised when those errors are fixed).
- Make
unevaluatedPropertiesmessages even weaker than "allOf" and "anyOf" related errors in https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/exceptions.py#L19
I'd be happy to attempt a PR; do you have any thoughts about which approach is best?
- Linguagem predominante
- Python
- Estrelas
- 5k
- Forks
- 741
- Merge médio
- 4d 17h
- PRs com merge (30d)
- 6
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python-jsonschema/jsonschema
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python-jsonschema/jsonschema#1610 · 1 comentário ·
Mantenedores costumam responder em até 6 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
python-jsonschema/jsonschema#1588 · 2 comentários ·
Mantenedores costumam responder em até 6 dias
-
Iterator error contexts lose parent links and absolute pathsTalvez livre de novo @DawnofGenX assumiu há 59 dias e não há nenhum pull request aberto. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
python-jsonschema/jsonschema#1584 · 3 comentários ·
Mantenedores costumam responder em até 6 dias
-
regex format checker crashes with RecursionError on deeply nested patternsTalvez já em andamento @DawnofGenX assumiu há 59 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python-jsonschema/jsonschema#1538 · 1 comentário ·
Mantenedores costumam responder em até 6 dias
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponentTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. AbertaNeeds Test Upstream
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python-jsonschema/jsonschema#1511 · 1 comentário ·
Mantenedores costumam responder em até 6 dias
Todas as issues de python-jsonschema/jsonschema
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
Techiebutler/freeframe#687 ·
Mantenedores costumam responder em até 1 dia
-
bug verbose GC
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
IBM/javacore-analyser#677 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 79/100
Mantenedores costumam responder em até 2 dias
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
NousResearch/hermes-agent#163932 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's fileTalvez já em andamento @Beehtrix assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
zilliztech/memsearch#907 · 1 comentário ·
Mantenedores costumam responder em até 1 dia