UnboundLocalError: local variable 'model_field' on schemas.py by cartyc · Pull Request #4956 · encode/django-rest-framework (original) (raw)

Description

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.