Open MarSoft opened 3 years ago
I think it's more of a python issue. We don't face the same issue when defining the field as an Embedded doc with its own class. Python is not able to interpret dicts using dots, whereas Mongodb, which is closer to JS is. If you are able to define the structure of the DictField as an EmbeddedDoc, might make it easier
@MarSoft is right, MongoEngine tracks the fields that are being changed through _changed_fields
using a "dot-delimited" convention to describe the path.
I'm not sure why the "dot-delimited" convention was chosen in the first place in _changed_fields, a tuple indeed sound like a better approach. I know it's useful for embedded fields and for list fields.
I don't think it would be such a big work to do the change but there might be edge cases that I'm not considering here
Is this issue still in 0.25.0 ? We use mongoengine in production and we have the same error 'Nonetype' object has no attribute '_reverse_db_field_map'
but we're not sure at all where it could come from.
I do not reproduce OP bug by testing locally. In what conditions is this crash occurring ?
Seems to only be an issue with object.save() - object.update(field=updatedField) works
We in the end had a problem with dots if field keys as well
Consider the following code:
I think this should work, because MongoDB allows dots in dict key names as of version 3.6. But in fact I get the following error:
After some digging I found that
_clear_changed_fields
takes list of string keys from_get_changed_fields()
where each key is a dot-delimited path into the object. Obviously this doesn't play well with keys containing dots.I think it would be safer to store keys as tuples rather than dot-delimited strings, but it will probably involve too many changes?
Tested with
MongoEngine==0.23.1
andpython 3.9.5
.