alecthomas / alecthomas/voluptuous

Validating a Mapping that isn't a dict fails

オープン
#299 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
1.9k
フォーク
237
PR マージ指標
30日以内にマージされた PR はありません

説明

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`?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。