MongoEngine / MongoEngine/mongoengine

If I use exclude I can lose my information

Open
#1,085 4 comments 0 reactions 1 assignee View on GitHub

@touilleMan is already working on this.

Since Sep 22, 2015.

Bug High Priority
Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

If I use exclude I can lose my information. Here is what happens in my auth middleware:

         17         if session_key:
         18             try:
         19                 user = User.objects.exclude('crm_data').get(id=session_key)
         20                 import ipdb; ipdb.set_trace()
         21             except User.DoesNotExist:
         22                 user = None
         23             else:
    ---> 24                 if not user.is_active:
         25                     ...

    # crm_data was not loaded, but was replaced with default value
    ipdb> user.crm_data
    CrmData(notes=[], tags=[])

    # but there are values in `crm_data` in the DB
    ipdb> User.objects.get(id=session_key).crm_data
    CrmData(notes=[], tags=[u'test'])

    # if I accidentally save the instance
    ipdb> user.save()
    ...

    # data in the db is lost
    ipdb> User.objects.get(id=session_key).crm_data
    CrmData(notes=[], tags=[])

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.