Skip to content

Commit

Permalink
Handle dynamic fieldnames that look like digits (MongoEngine#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Aug 7, 2013
1 parent 4731105 commit 5bcc454
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -4,6 +4,7 @@ Changelog

Changes in 0.8.4
================
- Handle dynamic fieldnames that look like digits (#434)
- Added get_user_document and improve mongo_auth module (#423)
- Added str representation of GridFSProxy (#424)
- Update transform to handle docs erroneously passed to unset (#416)
Expand Down
2 changes: 1 addition & 1 deletion mongoengine/base/document.py
Expand Up @@ -762,7 +762,7 @@ def _lookup_field(cls, parts):

for field_name in parts:
# Handle ListField indexing:
if field_name.isdigit():
if field_name.isdigit() and hasattr(field, 'field'):
new_field = field.field
fields.append(field_name)
continue
Expand Down
7 changes: 7 additions & 0 deletions tests/queryset/queryset.py
Expand Up @@ -3299,6 +3299,13 @@ class Test(Document):
Test.objects(test='foo').update_one(upsert=True, set__test='foo')
self.assertTrue('_cls' in Test._collection.find_one())

def test_update_upsert_looks_like_a_digit(self):
class MyDoc(DynamicDocument):
pass
MyDoc.drop_collection()
self.assertEqual(1, MyDoc.objects.update_one(upsert=True, inc__47=1))
self.assertEqual(MyDoc.objects.get()['47'], 1)

def test_read_preference(self):
class Bar(Document):
pass
Expand Down

0 comments on commit 5bcc454

Please sign in to comment.