alecthomas / alecthomas/voluptuous

Validating a Mapping that isn't a dict fails

Aperta
#299 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
1.9k
Fork
237
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

This is essentially the same issue as #125; it appears maybe this feature is now broken?

I, like #125, am attempting to validate an aiohttp request query arguments, which isn't a `dict`, but is a `Mapping`.

However, `voluptuous` requires a `dict`, as can be seen [here](https://github.com/alecthomas/voluptuous/blob/77ee5da9e33ccd0ec68f2b670d8ef0569c89041f/voluptuous/schema_builder.py#L499-L500); I see this in my stack trace:

```
Traceback (most recent call last):
File "…/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 221, in __call__
return self._compiled([], data)
File "…/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 504, in validate_dict
raise er.DictInvalid('expected a dictionary', path)
voluptuous.error.DictInvalid: expected a dictionary

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "…/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 422, in start
resp = yield from self._request_handler(request)
File "…/lib/python3.6/site-packages/aiohttp/web.py", line 306, in _handle
resp = yield from handler(request)
File "…/__main__.py", line 32, in wrapper
json_data = await func(*args, **kwargs)
File "…/__main__.py", line 88, in foo
validated_qargs = _SCHEMA(request.query)
File "…/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 225, in __call__
raise er.MultipleInvalid([e])
voluptuous.error.MultipleInvalid: expected a dictionary
```

I think it's as simple as changing that `dict` to `Mapping`?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.