-
Type:
Bug
-
Resolution: Done
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Environment:ubuntu linux mongodb 1.6.5
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Here's a code snippet illustrating the problem.
import pymongo
class DocumentClass(dict):
pass
conn = pymongo.Connection()
db = conn['tmp']
coll = db['tmp']
obj = DocumentClass()
obj['foo'] =
coll.save(obj)
print "original object:"
print type(obj)
print type(obj['foo'])
found = coll.find_one(as_class=DocumentClass)
print
print "found object:"
print type(found)
print type(found['foo'])
The output will be:
original object:
<class '_main_.DocumentClass'>
<type 'dict'>
found object:
<class '_main_.DocumentClass'>
<class '_main_.DocumentClass'>
Note how the type of the dict-valued field changed when the object is fetched from the database with as_class. I didn't expect this behavior, and I think it's wrong.
For example, I might want to define an _init_() on my DocumentClass that adds some default fields, computes values, etc. It's incorrect to run this code for each dict-valued field.