-
Notifications
You must be signed in to change notification settings - Fork 127
use_dot_notation = True causes InvalidDocument exception #245
Description
Mongokit causes a weird issue when I have a document structure below. I think the issue started when I added 3 new fields which are key-value type dictionary.
structure = {
'strategy_idx': unicode,
'strategy_type': IS(u"static", u"normal"),
'strategy_state': IS(u"draft", u"active", u"suspended"),
'strategy_size_params': {
unicode: OR(unicode, int, float)
},
'strategy_exec_params': {
unicode: OR(unicode, int, float)
},
'strategy_risk_params': {
unicode: OR(unicode, int, float)
},
}
I was able to insert a new record but when I tried to update the same object and call save(), I got an exception : InvalidDocument | Cannot encode object: {u'FillSize': 20, u'MinSize': 10}
The whole document is below if you want to check for its validity. I tested it using bson.BSON.encode(obj) and it works perfectly.
{u'strategy_size_params': {u'FillSize': 20, u'MinSize': 10},
u'strategy_type': u'static',
u'strategy_exec_params': {u'Max': 100, u'Avg': 40},
u'strategy_idx': u'TEST-77753-ID',
u'strategy_risk_params': {u'Kind': u'A', u'StopLoss': -60},
u'_id': ObjectId('5582668f75124f311344eb64'),
u'strategy_state': u'active'}
This error is with MongoKit 0.9.1.1
mongokit==0.9.1.1
pymongo==2.7
This error went away when I set 'use_dot_notation = False' It took me long time to figure out that this issues is not with the document but with its handling.
Related issue >
https://stackoverflow.com/questions/22049076/mongokit-nested-structure-save-error/22078430#