{"action":"created","issue":{"url":"https://api.github.com/repos/pyeve/cerberus/issues/458","repository_url":"https://api.github.com/repos/pyeve/cerberus","labels_url":"https://api.github.com/repos/pyeve/cerberus/issues/458/labels{/name}","comments_url":"https://api.github.com/repos/pyeve/cerberus/issues/458/comments","events_url":"https://api.github.com/repos/pyeve/cerberus/issues/458/events","html_url":"https://github.com/pyeve/cerberus/issues/458","id":390837298,"node_id":"MDU6SXNzdWUzOTA4MzcyOTg=","number":458,"title":"Unexpected TypeError raised on validation when using schema_registry and a list is passed instead of single value","user":{"login":"alexandrefvb","id":108050,"node_id":"MDQ6VXNlcjEwODA1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/108050?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrefvb","html_url":"https://github.com/alexandrefvb","followers_url":"https://api.github.com/users/alexandrefvb/followers","following_url":"https://api.github.com/users/alexandrefvb/following{/other_user}","gists_url":"https://api.github.com/users/alexandrefvb/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrefvb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrefvb/subscriptions","organizations_url":"https://api.github.com/users/alexandrefvb/orgs","repos_url":"https://api.github.com/users/alexandrefvb/repos","events_url":"https://api.github.com/users/alexandrefvb/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrefvb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-13T20:02:04Z","updated_at":"2018-12-13T20:14:46Z","closed_at":null,"author_association":"NONE","body":"Used Cerberus version: 1.2\r\n\r\n- [x] I have the capacity to improve the docs when my problem is solved.\r\n- [x] I have the capacity to submit a patch when a bug is identified.\r\n\r\n- [x] My question does not concern a practical use-case that I can't figure out\r\n      to solve.\r\n\r\n----\r\n\r\n#### Use-case abstract\r\n\r\nUsing schema_registry to define schemas of models with references between schemas.\r\n\r\n----\r\n\r\n#### Bug report / Feature request\r\n\r\nA unexpected TypeError is raised on this scenario:\r\n\r\n1. Define two schemas 'A' and 'B' on schema registry with 'A' referencing 'B' on a single value attribute\r\n2. Create a validator with schema 'A'\r\n3. Call validation method passing b value as a list\r\n\r\n```\r\n>>> from cerberus import schema_registry, Validator\r\n>>> schema_registry.add('A', { 'b': { 'schema': 'B' } })\r\n>>> schema_registry.add('B', { 'c': { 'type': 'string' } })\r\n>>> v = Validator('A')\r\n>>> v.validated({'b':{'c':'d'}})\r\n{'b': {'c': 'd'}}\r\n>>> v.validated({'b':[{'c':'d'}]})\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 895, in validated\r\n    self.validate(*args, **kwargs)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 870, in validate\r\n    self.__normalize_mapping(self.document, self.schema)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 617, in __normalize_mapping\r\n    self.__normalize_containers(mapping, schema)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 687, in __normalize_containers\r\n    self.__normalize_sequence(field, mapping, schema)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 744, in __normalize_sequence\r\n    result = validator.normalized(document, always_return_document=True)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 594, in normalized\r\n    self.__normalize_mapping(self.document, self.schema)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 608, in __normalize_mapping\r\n    self.__normalize_rename_fields(mapping, schema)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 761, in __normalize_rename_fields\r\n    self._normalize_rename(mapping, schema, field)\r\n  File \"/home/fidelis/workspaces/yandeh/b2b/b2b-api/venv/lib/python3.6/site-packages/cerberus/validator.py\", line 771, in _normalize_rename\r\n    if 'rename' in schema[field]:\r\nTypeError: argument of type 'NoneType' is not iterable\r\n\r\n```\r\n----\r\n\r\n#### Proposed solution\r\n\r\nChange _resolve_rules_set method of cerberus.Validator class from:\r\n\r\n```\r\n    def _resolve_rules_set(self, rules_set):\r\n        if isinstance(rules_set, Mapping):\r\n            return rules_set\r\n        elif isinstance(rules_set, _str_type):\r\n            return self.rules_set_registry.get(rules_set)\r\n        return None\r\n```\r\n\r\nto:\r\n\r\n```\r\n    def _resolve_rules_set(self, rules_set):\r\n        if isinstance(rules_set, Mapping):\r\n            return rules_set\r\n        elif isinstance(rules_set, _str_type):\r\n            return self.rules_set_registry.get(rules_set, {})\r\n        return None\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pyeve/cerberus/issues/comments/447105617","html_url":"https://github.com/pyeve/cerberus/issues/458#issuecomment-447105617","issue_url":"https://api.github.com/repos/pyeve/cerberus/issues/458","id":447105617,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NzEwNTYxNw==","user":{"login":"alexandrefvb","id":108050,"node_id":"MDQ6VXNlcjEwODA1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/108050?v=4","gravatar_id":"","url":"https://api.github.com/users/alexandrefvb","html_url":"https://github.com/alexandrefvb","followers_url":"https://api.github.com/users/alexandrefvb/followers","following_url":"https://api.github.com/users/alexandrefvb/following{/other_user}","gists_url":"https://api.github.com/users/alexandrefvb/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrefvb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrefvb/subscriptions","organizations_url":"https://api.github.com/users/alexandrefvb/orgs","repos_url":"https://api.github.com/users/alexandrefvb/repos","events_url":"https://api.github.com/users/alexandrefvb/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrefvb/received_events","type":"User","site_admin":false},"created_at":"2018-12-13T20:14:46Z","updated_at":"2018-12-13T20:14:46Z","author_association":"NONE","body":"the class to apply the fix is cerberus.BareValidator"}}
{"actor":{"display_login":"alexandrefvb"}}