{"action":"closed","issue":{"url":"https://api.github.com/repos/lamenezes/simple-model/issues/18","repository_url":"https://api.github.com/repos/lamenezes/simple-model","labels_url":"https://api.github.com/repos/lamenezes/simple-model/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/lamenezes/simple-model/issues/18/comments","events_url":"https://api.github.com/repos/lamenezes/simple-model/issues/18/events","html_url":"https://github.com/lamenezes/simple-model/issues/18","id":302734176,"number":18,"title":"Clean doesn't work without override","user":{"login":"rafaelhenrique","id":1902333,"avatar_url":"https://avatars3.githubusercontent.com/u/1902333?v=4","gravatar_id":"","url":"https://api.github.com/users/rafaelhenrique","html_url":"https://github.com/rafaelhenrique","followers_url":"https://api.github.com/users/rafaelhenrique/followers","following_url":"https://api.github.com/users/rafaelhenrique/following{/other_user}","gists_url":"https://api.github.com/users/rafaelhenrique/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelhenrique/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelhenrique/subscriptions","organizations_url":"https://api.github.com/users/rafaelhenrique/orgs","repos_url":"https://api.github.com/users/rafaelhenrique/repos","events_url":"https://api.github.com/users/rafaelhenrique/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelhenrique/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-06T14:58:44Z","updated_at":"2018-03-23T12:18:10Z","closed_at":"2018-03-23T12:18:10Z","author_association":"NONE","body":"I have model like this:\r\n\r\n```\r\nfrom decimal import Decimal\r\nfrom simple_model import Model\r\nfrom .utils import decimal as sanitize_decimal\r\n\r\nclass MyModel(Model):\r\n    name: str\r\n    value: Decimal\r\n    user: str\r\n\r\n    def clean_value(self, value):\r\n        return sanitize_decimal(value)\r\n```\r\n\r\nAnd I need a sanitized value because my value contains a comma. So I need to create an object like this:\r\n\r\n```\r\nmy_object = MyModel(name='Rafael Henrique', amount='23232,43', user='rafaelhenrique')\r\n```\r\n\r\nBut when I call clean this problem happens below:\r\n\r\n```\r\n>>> my_object = MyModel(name='Rafael Henrique', amount='23232,43', user='rafaelhenrique')\r\n>>> my_object.clean()\r\nTraceback (most recent call last):\r\n File \"<stdin>\", line 1, in <module>\r\n File \"/home/rafael/.virtualenvs/my-project/lib/python3.6/site-packages/simple_model/models.py\", line 122, in clean\r\n   clean_value = descriptor.clean(self, value)\r\n File \"/home/rafael/.virtualenvs/my-project/lib/python3.6/site-packages/simple_model/fields.py\", line 59, in clean\r\n   value = self.convert_to_type(instance, value)\r\n File \"/home/rafael/.virtualenvs/my-project/lib/python3.6/site-packages/simple_model/fields.py\", line 56, in convert_to_type\r\n   return field_type(value)\r\ndecimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]\r\n```\r\n\r\nTo \"solve\" this problem i need use this method (below) to override clean:\r\n\r\n```\r\n    def clean(self):\r\n        self.value = self.clean_value(self.value)\r\n        super().clean()\r\n```\r\n\r\nMy suggestion: pysimplemodel read the clean_\\<field\\> first and then call clean from the base class after."}}
{"actor":{"display_login":"lamenezes"}}