-
Notifications
You must be signed in to change notification settings - Fork 95
Description
Hi there.
I'm using mongodbforms for my Django application. I have a ListField of EmbeddedDocumentField and need to make a form out of it (Using embeddedformset_factory.). However the code won't run, returning the following error :
File "/home/jacques/.ve/ve_1/lib/python2.7/site-packages/mongodbforms/documents.py", line 919, in _get_embedded_field if (isinstance(field, EmbeddedDocumentField) and field.document_type == document) or \ UnboundLocalError: local variable 'field' referenced before assignment
So, after a very quick investigation, I found out the following piece of code inside mongodbforms/documents.py (line 917) :
emb_fields = [
f for f in parent_doc._fields.values()
if (isinstance(field, EmbeddedDocumentField) and field.document_type == document) or \
(isinstance(field, ListField) and
isinstance(field.field, EmbeddedDocumentField) and
field.field.document_type == document)
]...Which seems quite incorrect to me, because field is never instantiated in the loop. Hence, I patched it this way, replacing field with f :
emb_fields = [
f for f in parent_doc._fields.values()
if (isinstance(f, EmbeddedDocumentField) and f.document_type == document) or \
(isinstance(f, ListField) and
isinstance(f.field, EmbeddedDocumentField) and
f.field.document_type == document)
]Which now works properly. Is it possible to update the source ? (I'm not too familiar with Git so I don't want to make a mess of it.)
Have a nice day !