Repository: encode/django-rest-framework

Issue:
Module "oauth_provider.store.db" does not define an oauth store named "ModelStore"
After upgrading from 2.2.3 to 2.2.7, the following exception started occuring:

```
Traceback (most recent call last):
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/core/handlers/base.py", line 92, in get_response
    response = middleware_method(request)
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/middleware/common.py", line 69, in process_request
    if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/core/urlresolvers.py", line 551, in is_valid_path
    resolve(path, urlconf)
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/core/urlresolvers.py", line 440, in resolve
    return get_resolver(urlconf).resolve(path)
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/core/urlresolvers.py", line 319, in resolve
    for pattern in self.url_patterns:
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/core/urlresolvers.py", line 347, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/danilo/Projects/studentenportal2/../studentenportal2/urls.py", line 8, in <module>
    from apps.api import urls as api_urls
  File "/home/danilo/Projects/studentenportal2/../studentenportal2/apps/api/urls.py", line 4, in <module>
    from rest_framework.urlpatterns import format_suffix_patterns
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/rest_framework/urlpatterns.py", line 3, in <module>
    from rest_framework.compat import url, include
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/rest_framework/compat.py", line 475, in <module>
    from oauth_provider.store import store as oauth_provider_store
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/oauth_provider/store/__init__.py", line 177, in <module>
    store = get_store()
  File "/home/danilo/.virtualenvs/studentenportal/lib/python2.7/site-packages/oauth_provider/store/__init__.py", line 172, in get_store
    raise ImproperlyConfigured('Module "%s" does not define an oauth store named "%s"' % (module, attr))
ImproperlyConfigured: Module "oauth_provider.store.db" does not define an oauth store named "ModelStore"
```

I have not enabled OAuth. Grepping for oauth in my repository does not return any results.



Discussion:
Oh, I had oauth2 and django-oauth-plus installed. But didn't enable them in my code. After uninstalling them, it works again.

Just because I have those packages installed, you can't assume that I've also enabled and configured them :)


Resolving patch:
diff --git a/rest_framework/compat.py b/rest_framework/compat.py
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -6,6 +6,7 @@
 from __future__ import unicode_literals
 
 import django
+from django.core.exceptions import ImproperlyConfigured
 
 # Try to import six from Django, fallback to included `six`.
 try:
@@ -473,7 +474,7 @@ def apply_markdown(text):
 try:
     import oauth_provider
     from oauth_provider.store import store as oauth_provider_store
-except ImportError:
+except (ImportError, ImproperlyConfigured):
     oauth_provider = None
     oauth_provider_store = None
 


Test patch: