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: local variable 'model_field' on #4956

merged 1 commit into from Mar 10, 2017


Copy link

@cartyc cartyc commented Mar 10, 2017


First time pull request.

I was getting the following error when trying out the new api documentation support feature.

UnboundLocalError: local variable 'model_field' referenced before assignment

I found that if the try/except on model_field = model._meta.get_field(variable) failed it would simply pass and not set the model_field to None which would then cause an error at line 536

if model_field is not None and model_field.verbose_name:

Fixed this by telling the except to set model_field to None. Passed all the tests as per the guidelines.

…iled model_field was not set to None and would reult in an error
Copy link

jakemcdermott commented Mar 10, 2017

Hi. I wrote a test case for this. I'd be happy to PR it incase anyone wants it.

(It was part of a changeset to fix this issue but it looks like this PR already does that)


Copy link

tomchristie commented Mar 10, 2017

Closes #4955.

@@ -531,7 +531,7 @@ def get_path_fields(self, path, method, view):
model_field = model._meta.get_field(variable)
model_field = None # Set model_field to None so it doesn't fail test
Copy link

@tomchristie tomchristie Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, yup! We don't need the comment here, so drop that and this'll be good to go.

@tomchristie tomchristie merged commit bc2c76a into encode:master Mar 10, 2017
Copy link

tomchristie commented Mar 10, 2017

Thanks @cartyc, and welcome! 😎

@tomchristie tomchristie added this to the 3.6.2 Release milestone Mar 10, 2017
Copy link
Contributor Author

cartyc commented Mar 10, 2017

Thanks @tomchristie , Happy to help out :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants