tomchristie/django-rest-framework — pull request #2086 by beck (2014-11-18 06:37:07+00:00)
Title: Ensure _resolve_model does not return None

Under certain circumstances Django may return `None` with `get_model`:
https://github.com/django/django/blob/1.6.7/django/db/models/loading.py#L265

It usually happens with circular imports so it is important that DRF excepts early, otherwise fault happens downstream and is much more difficult to debug.

The downstream failure looks something like:
```
Traceback (most recent call last):
File "/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 102, in inner_run
self.validate(display_num_errors=True)
File "/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
...
[code with hidden circular import]
....
File "/lib/python2.7/site-packages/rest_framework/serializers.py", line 204, in __init__
self.fields = self.get_fields()
File "/lib/python2.7/site-packages/rest_framework/serializers.py", line 240, in get_fields
default_fields = self.get_default_fields()
File "/lib/python2.7/site-packages/rest_framework/serializers.py", line 722, in get_default_fields
field = self.get_related_field(model_field, related_model, to_many)
File "/lib/python2.7/site-packages/rest_framework/serializers.py", line 824, in get_related_field
'queryset': related_model._default_manager,
AttributeError: 'NoneType' object has no attribute '_default_manager'
```