-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error while using "db_field" parameter in multi-level embedded documents #904
Comments
I narrowed it down a bit and found in for field_name, field in fields.iteritems():
field._auto_dereference = _auto_dereference
if field.db_field in data:
value = data[field.db_field] As far as I understand whats going on the problem resides in the line: if field.db_field in data: where So i was looking up, where data is coming from and found: data = dict(("%s" % key, value) for key, value in son.iteritems()) there is obviously no conversation from python field name to db field name. So I came up with a little patch: # class if unavailable
class_name = son.get('_cls', cls._class_name)
- data = dict(("%s" % key, value) for key, value in son.iteritems())
+ data = dict(("%s" % cls._db_field_map.get(key,key), value) for key, value in son.items())
# Return correct subclass for document type
if class_name != cls._class_name: This seems to work for my short testing, but I'm actually not sure if I will break something later or if this is good practice. I'm also not sure, if I'm actually supposed to use Before I create a pull request, it would be nice if a mongoengine developer could give me some input. Thanks a lot!! |
… in multi-level embedded documents
nice job @ms5 ! Would you eventually make a PR out of this? Formalising also the description above inside a test? It would be great ! |
ok, no problem. give me some time to write the tests, I'll then create a pull request. |
…error case I reported in the issue report.
The following code is an example to reconstruct what's going wrong. The main problem seems to be the use of
db_field
in the second level of the embedded document (In the example this isclass B
)If I run this, it throws an exception:
But it runs through if I remove the
db_field
attribute inclass B
:While digging in to this problem I found out that the exception is actually correct when saying the Document has the wrong format.
while running a simple print on the working an non working version, the type differs.
The text was updated successfully, but these errors were encountered: