Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With context_managers.no_dereference, the query results still dereference data #1245

Closed
frankyao47 opened this issue Mar 2, 2016 · 0 comments · Fixed by #2830
Closed

With context_managers.no_dereference, the query results still dereference data #1245

frankyao47 opened this issue Mar 2, 2016 · 0 comments · Fixed by #2830
Labels

Comments

@frankyao47
Copy link

In MongoEngineDoc, it says that

with no_dereference(Post) as Post: 
    post = Post.objects.first()

works the similar way as

post = Post.objects.no_dereference().first()

Both of them can turn off dereference. However the first one doesn't seems work and the result still dereference data. Is that a bug?

Version
mongoengine (0.10.6)

Platform
Ubuntu 14.04

Test Code

#!/usr/bin/env python
#coding: utf-8

from mongoengine import *
from mongoengine.context_managers import no_dereference


connect('issueTest', host='localhost', port=27017)

class User(Document):
    email = StringField(required=True)


class Post(Document):
    title = StringField(max_length=120, required=True)
    author = ReferenceField(User)
    tags = ListField(StringField(max_length=30))

user = User(email="[email protected]")
user.save()

post = Post(title="testPost", tags=["test", "test2"], author=user)
post.save()

with no_dereference(Post) as Post:
    post = Post.objects().first()
    print post.title, post.tags, post.author

post = Post.objects().first()
print post.title, post.tags, post.author

post = Post.objects().no_dereference().first()
print post.title, post.tags, post.author

Output

testPost [u'test', u'test2'] User object
testPost [u'test', u'test2'] User object
testPost [u'test', u'test2'] DBRef('user', ObjectId('56d68dad8649a53948aa5b90'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants