Skip to content

Commit 3a5b377

Browse files
committed
Use ImproperlyConfigured when model meta lookup fails
1 parent 6fbd23a commit 3a5b377

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

rest_framework/utils/model_meta.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Usage: `get_field_info(model)` returns a `FieldInfo` instance.
77
"""
88
from collections import namedtuple
9+
from django.core.exceptions import ImproperlyConfigured
910
from django.db import models
1011
from django.utils import six
1112
from rest_framework.compat import OrderedDict
@@ -44,9 +45,9 @@ def _resolve_model(obj):
4445
if isinstance(obj, six.string_types) and len(obj.split('.')) == 2:
4546
app_name, model_name = obj.split('.')
4647
resolved_model = models.get_model(app_name, model_name)
47-
if not resolved_model:
48-
raise ValueError("Django did not return a model for "
49-
"{0}.{1}".format(app_name, model_name))
48+
if resolved_model is None:
49+
msg = "Django did not return a model for {0}.{1}"
50+
raise ImproperlyConfigured(msg.format(app_name, model_name))
5051
return resolved_model
5152
elif inspect.isclass(obj) and issubclass(obj, models.Model):
5253
return obj

tests/test_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import unicode_literals
2+
from django.core.exceptions import ImproperlyConfigured
23
from django.conf.urls import patterns, url
34
from django.test import TestCase
45
from django.utils import six
@@ -161,5 +162,5 @@ def tearDown(self):
161162
rest_framework.utils.model_meta.models.get_model = self.get_model
162163

163164
def test_blows_up_if_model_does_not_resolve(self):
164-
with self.assertRaises(ValueError):
165+
with self.assertRaises(ImproperlyConfigured):
165166
_resolve_model('tests.BasicModel')

0 commit comments

Comments
 (0)