Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mongoengine/queryset/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,14 +1731,14 @@ def _fields_to_dbfields(self, fields):
for x in document._subclasses][1:]
for field in fields:
try:
field = '.'.join(f.db_field for f in
field = '.'.join(f if isinstance(f, six.string_types) else f.db_field for f in
document._lookup_field(field.split('.')))
ret.append(field)
except LookUpError as err:
found = False
for subdoc in subclasses:
try:
subfield = '.'.join(f.db_field for f in
subfield = '.'.join(f if isinstance(f, six.string_types) else f.db_field for f in
subdoc._lookup_field(field.split('.')))
ret.append(subfield)
found = True
Expand Down
9 changes: 8 additions & 1 deletion tests/queryset/field_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,18 @@ class Comment(EmbeddedDocument):
title = StringField()
text = StringField()

class VariousData(EmbeddedDocument):
some = BooleanField()

class BlogPost(Document):
content = StringField()
author = EmbeddedDocumentField(User)
comments = ListField(EmbeddedDocumentField(Comment))
various = MapField(field=EmbeddedDocumentField(VariousData))

BlogPost.drop_collection()

post = BlogPost(content='Had a good coffee today...')
post = BlogPost(content='Had a good coffee today...', various={'test_dynamic':{'some': True}})
post.author = User(name='Test User')
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
post.save()
Expand All @@ -215,6 +219,9 @@ class BlogPost(Document):
self.assertEqual(obj.author.name, 'Test User')
self.assertEqual(obj.comments, [])

obj = BlogPost.objects.only('various.test_dynamic.some').get()
self.assertEqual(obj.various["test_dynamic"].some, True)

obj = BlogPost.objects.only('content', 'comments.title',).get()
self.assertEqual(obj.content, 'Had a good coffee today...')
self.assertEqual(obj.author, None)
Expand Down