Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
3a5b3772
Commit
3a5b3772
authored
Nov 28, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ImproperlyConfigured when model meta lookup fails
parent
6fbd23ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
rest_framework/utils/model_meta.py
+4
-3
tests/test_utils.py
+2
-1
No files found.
rest_framework/utils/model_meta.py
View file @
3a5b3772
...
@@ -6,6 +6,7 @@ relationships and their associated metadata.
...
@@ -6,6 +6,7 @@ relationships and their associated metadata.
Usage: `get_field_info(model)` returns a `FieldInfo` instance.
Usage: `get_field_info(model)` returns a `FieldInfo` instance.
"""
"""
from
collections
import
namedtuple
from
collections
import
namedtuple
from
django.core.exceptions
import
ImproperlyConfigured
from
django.db
import
models
from
django.db
import
models
from
django.utils
import
six
from
django.utils
import
six
from
rest_framework.compat
import
OrderedDict
from
rest_framework.compat
import
OrderedDict
...
@@ -44,9 +45,9 @@ def _resolve_model(obj):
...
@@ -44,9 +45,9 @@ def _resolve_model(obj):
if
isinstance
(
obj
,
six
.
string_types
)
and
len
(
obj
.
split
(
'.'
))
==
2
:
if
isinstance
(
obj
,
six
.
string_types
)
and
len
(
obj
.
split
(
'.'
))
==
2
:
app_name
,
model_name
=
obj
.
split
(
'.'
)
app_name
,
model_name
=
obj
.
split
(
'.'
)
resolved_model
=
models
.
get_model
(
app_name
,
model_name
)
resolved_model
=
models
.
get_model
(
app_name
,
model_name
)
if
not
resolved_model
:
if
resolved_model
is
None
:
raise
ValueError
(
"Django did not return a model for
"
msg
=
"Django did not return a model for {0}.{1}
"
"{0}.{1}"
.
format
(
app_name
,
model_name
))
raise
ImproperlyConfigured
(
msg
.
format
(
app_name
,
model_name
))
return
resolved_model
return
resolved_model
elif
inspect
.
isclass
(
obj
)
and
issubclass
(
obj
,
models
.
Model
):
elif
inspect
.
isclass
(
obj
)
and
issubclass
(
obj
,
models
.
Model
):
return
obj
return
obj
...
...
tests/test_utils.py
View file @
3a5b3772
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.core.exceptions
import
ImproperlyConfigured
from
django.conf.urls
import
patterns
,
url
from
django.conf.urls
import
patterns
,
url
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.utils
import
six
from
django.utils
import
six
...
@@ -161,5 +162,5 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
...
@@ -161,5 +162,5 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
rest_framework
.
utils
.
model_meta
.
models
.
get_model
=
self
.
get_model
rest_framework
.
utils
.
model_meta
.
models
.
get_model
=
self
.
get_model
def
test_blows_up_if_model_does_not_resolve
(
self
):
def
test_blows_up_if_model_does_not_resolve
(
self
):
with
self
.
assertRaises
(
ValueError
):
with
self
.
assertRaises
(
ImproperlyConfigured
):
_resolve_model
(
'tests.BasicModel'
)
_resolve_model
(
'tests.BasicModel'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment