{"action":"created","issue":{"url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/1085","labels_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/1085/labels{/name}","comments_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/1085/comments","events_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/1085/events","html_url":"https://github.com/MongoEngine/mongoengine/issues/1085","id":97246871,"number":1085,"title":"If I use exclude I can lose my information","user":{"login":"warvariuc","id":1035452,"avatar_url":"https://avatars.githubusercontent.com/u/1035452?v=3","gravatar_id":"","url":"https://api.github.com/users/warvariuc","html_url":"https://github.com/warvariuc","followers_url":"https://api.github.com/users/warvariuc/followers","following_url":"https://api.github.com/users/warvariuc/following{/other_user}","gists_url":"https://api.github.com/users/warvariuc/gists{/gist_id}","starred_url":"https://api.github.com/users/warvariuc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/warvariuc/subscriptions","organizations_url":"https://api.github.com/users/warvariuc/orgs","repos_url":"https://api.github.com/users/warvariuc/repos","events_url":"https://api.github.com/users/warvariuc/events{/privacy}","received_events_url":"https://api.github.com/users/warvariuc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-25T18:55:56Z","updated_at":"2015-08-17T18:20:43Z","closed_at":null,"body":"If I use [`exclude`](http://docs.mongoengine.org/en/latest/apireference.html#mongoengine.queryset.QuerySet.exclude) I can lose my information. Here is what happens in my auth middleware:\r\n```\r\n         17         if session_key:\r\n         18             try:\r\n         19                 user = User.objects.exclude('crm_data').get(id=session_key)\r\n         20                 import ipdb; ipdb.set_trace()\r\n         21             except User.DoesNotExist:\r\n         22                 user = None\r\n         23             else:\r\n    ---> 24                 if not user.is_active:\r\n         25                     ...\r\n    \r\n    # crm_data was not loaded, but was replaced with default value\r\n    ipdb> user.crm_data\r\n    CrmData(notes=[], tags=[])\r\n    \r\n    # but there are values in `crm_data` in the DB\r\n    ipdb> User.objects.get(id=session_key).crm_data\r\n    CrmData(notes=[], tags=[u'test'])\r\n    \r\n    # if I accidentally save the instance\r\n    ipdb> user.save()\r\n    ...\r\n    \r\n    # data in the db is lost\r\n    ipdb> User.objects.get(id=session_key).crm_data\r\n    CrmData(notes=[], tags=[])\r\n```"},"comment":{"url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/comments/131915949","html_url":"https://github.com/MongoEngine/mongoengine/issues/1085#issuecomment-131915949","issue_url":"https://api.github.com/repos/MongoEngine/mongoengine/issues/1085","id":131915949,"user":{"login":"warvariuc","id":1035452,"avatar_url":"https://avatars.githubusercontent.com/u/1035452?v=3","gravatar_id":"","url":"https://api.github.com/users/warvariuc","html_url":"https://github.com/warvariuc","followers_url":"https://api.github.com/users/warvariuc/followers","following_url":"https://api.github.com/users/warvariuc/following{/other_user}","gists_url":"https://api.github.com/users/warvariuc/gists{/gist_id}","starred_url":"https://api.github.com/users/warvariuc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/warvariuc/subscriptions","organizations_url":"https://api.github.com/users/warvariuc/orgs","repos_url":"https://api.github.com/users/warvariuc/repos","events_url":"https://api.github.com/users/warvariuc/events{/privacy}","received_events_url":"https://api.github.com/users/warvariuc/received_events","type":"User","site_admin":false},"created_at":"2015-08-17T18:20:43Z","updated_at":"2015-08-17T18:20:43Z","body":"```\r\nPython 2.7.8 (default, Oct 20 2014, 15:05:19) \r\n>>> from brain.models.auth import User\r\n\r\n>>> user = User.objects.get(email='victor.***')\r\n\r\n>>> user.crm_data\r\nCrmData(notes=[], tags=[u'test'])\r\n\r\n>>> user = User.objects.only('email').get(email='victor.***')\r\n\r\n>>> user.crm_data\r\nCrmData(notes=[], tags=[])\r\n\r\n>>> user.save()\r\nUser(id='54ecaa791fdf932a6053ecf5', crm_data=CrmData(notes=[], tags=[]), email=u'victor.***', ...)\r\n\r\n>>> User.objects.get(email='victor.***').crm_data\r\nCrmData(notes=[], tags=[])\r\n\r\n>>> import mongoengine\r\n\r\n>>> mongoengine.__version__\r\n>>> '0.10.0'\r\n\r\n```\r\nModel:\r\n```\r\nclass CrmNote(EmbeddedDocument):\r\n    text = me.StringField(required=True)\r\n    author_id = me.ObjectIdField()\r\n    created_at = me.DateTimeField(default=datetime.utcnow)\r\n\r\nclass CrmData(EmbeddedDocument):\r\n    tags = me.ListField(me.StringField(min_length=2, max_length=20))\r\n    notes = me.ListField(me.EmbeddedDocumentField(CrmNote))\r\n\r\nclass User(Document):\r\n    crm_data = me.EmbeddedDocumentField(CrmData, default=CrmData)\r\n    ...\r\n```"}}