mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
Fix exception causes in relations.py
This commit is contained in:
parent
b677b7b15d
commit
e943e64914
|
@ -308,12 +308,12 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return queryset.get(**lookup_kwargs)
|
return queryset.get(**lookup_kwargs)
|
||||||
except ValueError:
|
except ValueError as e:
|
||||||
exc = ObjectValueError(str(sys.exc_info()[1]))
|
exc = ObjectValueError(str(sys.exc_info()[1]))
|
||||||
raise exc.with_traceback(sys.exc_info()[2])
|
raise exc.with_traceback(sys.exc_info()[2]) from e
|
||||||
except TypeError:
|
except TypeError as e:
|
||||||
exc = ObjectTypeError(str(sys.exc_info()[1]))
|
exc = ObjectTypeError(str(sys.exc_info()[1]))
|
||||||
raise exc.with_traceback(sys.exc_info()[2])
|
raise exc.with_traceback(sys.exc_info()[2]) from e
|
||||||
|
|
||||||
def get_url(self, obj, view_name, request, format):
|
def get_url(self, obj, view_name, request, format):
|
||||||
"""
|
"""
|
||||||
|
@ -391,7 +391,7 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
# Return the hyperlink, or error if incorrectly configured.
|
# Return the hyperlink, or error if incorrectly configured.
|
||||||
try:
|
try:
|
||||||
url = self.get_url(value, self.view_name, request, format)
|
url = self.get_url(value, self.view_name, request, format)
|
||||||
except NoReverseMatch:
|
except NoReverseMatch as e:
|
||||||
msg = (
|
msg = (
|
||||||
'Could not resolve URL for hyperlinked relationship using '
|
'Could not resolve URL for hyperlinked relationship using '
|
||||||
'view name "%s". You may have failed to include the related '
|
'view name "%s". You may have failed to include the related '
|
||||||
|
@ -405,7 +405,7 @@ class HyperlinkedRelatedField(RelatedField):
|
||||||
"was %s, which may be why it didn't match any "
|
"was %s, which may be why it didn't match any "
|
||||||
"entries in your URL conf." % value_string
|
"entries in your URL conf." % value_string
|
||||||
)
|
)
|
||||||
raise ImproperlyConfigured(msg % self.view_name)
|
raise ImproperlyConfigured(msg % self.view_name) from e
|
||||||
|
|
||||||
if url is None:
|
if url is None:
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user