{"action":"created","issue":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/713","repository_url":"https://api.github.com/repos/marshmallow-code/marshmallow","labels_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/713/labels{/name}","comments_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/713/comments","events_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/713/events","html_url":"https://github.com/marshmallow-code/marshmallow/issues/713","id":285488488,"number":713,"title":"Empty strings as None (revisited)","user":{"login":"csingley","id":398996,"avatar_url":"https://avatars1.githubusercontent.com/u/398996?v=4","gravatar_id":"","url":"https://api.github.com/users/csingley","html_url":"https://github.com/csingley","followers_url":"https://api.github.com/users/csingley/followers","following_url":"https://api.github.com/users/csingley/following{/other_user}","gists_url":"https://api.github.com/users/csingley/gists{/gist_id}","starred_url":"https://api.github.com/users/csingley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csingley/subscriptions","organizations_url":"https://api.github.com/users/csingley/orgs","repos_url":"https://api.github.com/users/csingley/repos","events_url":"https://api.github.com/users/csingley/events{/privacy}","received_events_url":"https://api.github.com/users/csingley/received_events","type":"User","site_admin":false},"labels":[{"id":96590028,"url":"https://api.github.com/repos/marshmallow-code/marshmallow/labels/feedback%20welcome","name":"feedback welcome","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-01-02T17:26:19Z","updated_at":"2018-04-03T14:26:10Z","closed_at":null,"author_association":"NONE","body":"I'd like to revisit this suggestion - allowing empty strings to be interpreted as None:\r\n\r\nhttps://github.com/marshmallow-code/marshmallow/issues/543\r\n\r\nI understand the sentiment of the response: \"it's a bad idea to support that\".  However, that's not sufficient for some use cases.\r\n\r\nFor example, right now I'm trying to use marshmallow to convert an XML format where null values are sent as empty strings.  I don't get to control the XML format.\r\n\r\nI think it's entirely reasonable for a Field to interpret a null datestring (or a null decimal string) as None, and control via `allow_none` whether to pass that.  I don't think it's reasonable to fall down and say \"the NULL value defined by your format is invalid, and we're not going to allow you to express that\".  This just forces a lot of ugly preprocessing workarounds onto library users, who need to clutter their code with superfluous, bug-prone `value = value or None` type declarations... thereby mixing format definition code in the middle of application code, which makes it hard to use marshmallow to write good code for these use cases.\r\n\r\nI feel that the right place to define a format is, well, in the Schema class definition.  A patch to accomplish this is simple:\r\n\r\n- add an attribute to fields.Field, e.g. `null_values = {None}`\r\n- change fields.Field.deserialize() line 263 as follows:\r\n`if getattr(self, 'allow_none', False) is True and value in self.null_values:\r\n    return None`\r\n\r\nWe can stop there, and allow users to support their nasty unhygienic formats by overriding null_values in a custom subclass... or even take it a step further and allow first-class support for text-only formats by directly setting `null_values = {None, ''}` for fields.Decimal, fields.DateTime, fields.Date, fields.Time, etc.  By Zeus, maybe even fields.Integer could treat empty strings as None!!\r\n\r\nI'm happy to submit a PR to that effect, but I'd like to see where the developers' heads are at vis-a-vis using marshmallow for non-JSON formats before wasting anybody's time.\r\n\r\nThanks, and happy new year!"},"comment":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/comments/378268900","html_url":"https://github.com/marshmallow-code/marshmallow/issues/713#issuecomment-378268900","issue_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/713","id":378268900,"user":{"login":"csingley","id":398996,"avatar_url":"https://avatars1.githubusercontent.com/u/398996?v=4","gravatar_id":"","url":"https://api.github.com/users/csingley","html_url":"https://github.com/csingley","followers_url":"https://api.github.com/users/csingley/followers","following_url":"https://api.github.com/users/csingley/following{/other_user}","gists_url":"https://api.github.com/users/csingley/gists{/gist_id}","starred_url":"https://api.github.com/users/csingley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csingley/subscriptions","organizations_url":"https://api.github.com/users/csingley/orgs","repos_url":"https://api.github.com/users/csingley/repos","events_url":"https://api.github.com/users/csingley/events{/privacy}","received_events_url":"https://api.github.com/users/csingley/received_events","type":"User","site_admin":false},"created_at":"2018-04-03T14:26:10Z","updated_at":"2018-04-03T14:26:10Z","author_association":"NONE","body":"I've got no skin in the game at this point, but from a user's point of view I think the mixin proposal is pretty reasonable (although not surprisingly I prefer my own approach... who doesn't?)  Maybe a documentation enhancement outlining the NoneMixin pattern would be a good place to start?\r\n\r\n@lafrech - re: missing vs None - that would work fine for my specific case, but these two things can sometimes require different handling. If the data protocol changes, and a new field is added, you might want to have your code do one thing if the field is missing (old protocol) vs. blank (new protocol, default value).  Obviously this doesn't really apply to web forms, but I'd imagine in general you'd want to discriminate between the case where the field is empty and the case where it's simply not sent in the data stream.\r\n\r\nAnyway, that's enough back seat driving from me!  Cheers, and thanks for your work."}}
{"actor":{"display_login":"csingley"}}