{"action":"created","issue":{"url":"https://api.github.com/repos/MongoEngine/flask-mongoengine/issues/148","labels_url":"https://api.github.com/repos/MongoEngine/flask-mongoengine/issues/148/labels{/name}","comments_url":"https://api.github.com/repos/MongoEngine/flask-mongoengine/issues/148/comments","events_url":"https://api.github.com/repos/MongoEngine/flask-mongoengine/issues/148/events","html_url":"https://github.com/MongoEngine/flask-mongoengine/issues/148","id":78660201,"number":148,"title":"QuerySetSelectMultipleField does not allow zeroing out of data","user":{"login":"Ssawa","id":5949756,"avatar_url":"https://avatars.githubusercontent.com/u/5949756?v=3","gravatar_id":"","url":"https://api.github.com/users/Ssawa","html_url":"https://github.com/Ssawa","followers_url":"https://api.github.com/users/Ssawa/followers","following_url":"https://api.github.com/users/Ssawa/following{/other_user}","gists_url":"https://api.github.com/users/Ssawa/gists{/gist_id}","starred_url":"https://api.github.com/users/Ssawa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ssawa/subscriptions","organizations_url":"https://api.github.com/users/Ssawa/orgs","repos_url":"https://api.github.com/users/Ssawa/repos","events_url":"https://api.github.com/users/Ssawa/events{/privacy}","received_events_url":"https://api.github.com/users/Ssawa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-20T19:24:15Z","updated_at":"2015-05-20T19:33:09Z","closed_at":null,"body":"If you try to erase the value of an existing QuerySetSelectMultipleField (field is set to ['foo', 'bar',], you want to set it to []) the `if valuelist` condition in process_formdata prevents you from setting the value to None if it has already been set, as the data field is never changed. (This has nothing to do with validation and the allow_blank flag has no bearing).\r\n\r\nCan be fixed pretty easily by adding an:\r\n\r\n    else:\r\n        self.data = None\r\nat the end, so a complete example would look like:\r\n\r\n    def process_formdata(self, valuelist):\r\n        if valuelist:\r\n            if valuelist[0] == '__None':\r\n                self.data = None\r\n            else:\r\n                if not self.queryset:\r\n                    self.data = None\r\n                    return\r\n\r\n                self.queryset.rewind()\r\n                self.data = [obj for obj in self.queryset if str(obj.id) in valuelist]\r\n                if not len(self.data):\r\n                    self.data = None\r\n        else:\r\n            self.data = None\r\n"},"comment":{"url":"https://api.github.com/repos/MongoEngine/flask-mongoengine/issues/comments/104007525","html_url":"https://github.com/MongoEngine/flask-mongoengine/issues/148#issuecomment-104007525","issue_url":"https://api.github.com/repos/MongoEngine/flask-mongoengine/issues/148","id":104007525,"user":{"login":"Ssawa","id":5949756,"avatar_url":"https://avatars.githubusercontent.com/u/5949756?v=3","gravatar_id":"","url":"https://api.github.com/users/Ssawa","html_url":"https://github.com/Ssawa","followers_url":"https://api.github.com/users/Ssawa/followers","following_url":"https://api.github.com/users/Ssawa/following{/other_user}","gists_url":"https://api.github.com/users/Ssawa/gists{/gist_id}","starred_url":"https://api.github.com/users/Ssawa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ssawa/subscriptions","organizations_url":"https://api.github.com/users/Ssawa/orgs","repos_url":"https://api.github.com/users/Ssawa/repos","events_url":"https://api.github.com/users/Ssawa/events{/privacy}","received_events_url":"https://api.github.com/users/Ssawa/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T19:33:09Z","updated_at":"2015-05-20T19:33:09Z","body":"Alternatively I suppose you can instead make sure that the first element of valuelist is set to '__None' when no formdata is present but I've never seen this behavior in any of my ModelSelectMultipleFields"}}