Merge remote-tracking branch 'origin/pr/240'
This commit is contained in:
commit
4db339c5f4
@ -1207,7 +1207,7 @@ class BaseDocument(object):
|
||||
for p in parts:
|
||||
if isinstance(d, DBRef):
|
||||
break
|
||||
elif p.isdigit():
|
||||
elif isinstance(d, list) and p.isdigit():
|
||||
d = d[int(p)]
|
||||
elif hasattr(d, 'get'):
|
||||
d = d.get(p)
|
||||
@ -1238,7 +1238,7 @@ class BaseDocument(object):
|
||||
parts = path.split('.')
|
||||
db_field_name = parts.pop()
|
||||
for p in parts:
|
||||
if p.isdigit():
|
||||
if isinstance(d, list) and p.isdigit():
|
||||
d = d[int(p)]
|
||||
elif (hasattr(d, '__getattribute__') and
|
||||
not isinstance(d, dict)):
|
||||
|
@ -965,6 +965,24 @@ class FieldTest(unittest.TestCase):
|
||||
doc = self.db.test.find_one()
|
||||
self.assertEqual(doc['x']['DICTIONARY_KEY']['i'], 2)
|
||||
|
||||
def test_mapfield_numerical_index(self):
|
||||
"""Ensure that MapField accept numeric strings as indexes."""
|
||||
class Embedded(EmbeddedDocument):
|
||||
name = StringField()
|
||||
|
||||
class Test(Document):
|
||||
my_map = MapField(EmbeddedDocumentField(Embedded))
|
||||
|
||||
Test.drop_collection()
|
||||
|
||||
test = Test()
|
||||
test.my_map['1'] = Embedded(name='test')
|
||||
test.save()
|
||||
test.my_map['1'].name = 'test updated'
|
||||
test.save()
|
||||
|
||||
Test.drop_collection()
|
||||
|
||||
def test_map_field_lookup(self):
|
||||
"""Ensure MapField lookups succeed on Fields without a lookup method"""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user