python - mongoengine embeded document in a DynamicField -
i try embed document dynamic field. when try access later, it's not document object anymore, it's dict.
here example code i've made up:
#defining documents class embed(embeddeddocument): field_1 = stringfield(db_field='f') class doc(document): myid = intfield(required=true, unique=true, primary_key=true) embed_me = dynamicfield(db_field='e') field_x = stringfield(db_field='x')
then create new document , save it:
connect('test') # embedded part embed = embed(field_1='this test') # document embedded document doc = doc(pk=2) doc.embed_me = embed doc.save()
so far ok. in db:
# > db.doc.find() # { "_id" : 1, "e" : { "f" : "this test", "_cls" : "embed" } }
but now, if request document , try access value embedded document exception:
doc, c = doc.objects.get_or_create(pk=1)
just reference: access in main doc works
print doc.field_x > none
also reference: dict looks okay, except names embedded doc not translated
print doc.__dict__ > {'_created': false, '_data': {'myid': 1, 'embed_me': {u'_cls': u'embed', u'f': u'this test'}, 'field_x': none}, '_changed_fields': [], '_initialised': true}
and now, while try access embedded doc, exception rises
print doc.embed_me.field_1 > file "embed_err.py", line 31, in <module> print doc.embed_me.field_1 attributeerror: 'dict' object has no attribute 'field_1
what type it?
type(doc.embed_me) > <type 'dict'>
it looks embedded document not translated in object. i'm not sure if bug or if misunderstand concept. advice.
in 0.8.3 have manually reconstruct it, bug - opened #449 , fixed in master. 0.8.4 due later week.
Comments
Post a Comment