Skip to content
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

UnboundLocalError in documents.py at line 919 #67

Open
azthenaa-medivo opened this issue Jun 18, 2014 · 0 comments
Open

UnboundLocalError in documents.py at line 919 #67

azthenaa-medivo opened this issue Jun 18, 2014 · 0 comments

Comments

@azthenaa-medivo
Copy link

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant