mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
Improve Create to show the original exception traceback (#3508)
This commit is contained in:
parent
a335309b33
commit
d540f0262b
|
@ -12,6 +12,7 @@ response content is handled by parsers and renderers.
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import traceback
|
||||
import warnings
|
||||
|
||||
from django.db import models
|
||||
|
@ -870,19 +871,20 @@ class ModelSerializer(Serializer):
|
|||
|
||||
try:
|
||||
instance = ModelClass.objects.create(**validated_data)
|
||||
except TypeError as exc:
|
||||
except TypeError:
|
||||
tb = traceback.format_exc()
|
||||
msg = (
|
||||
'Got a `TypeError` when calling `%s.objects.create()`. '
|
||||
'This may be because you have a writable field on the '
|
||||
'serializer class that is not a valid argument to '
|
||||
'`%s.objects.create()`. You may need to make the field '
|
||||
'read-only, or override the %s.create() method to handle '
|
||||
'this correctly.\nOriginal exception text was: %s.' %
|
||||
'this correctly.\nOriginal exception was:\n %s' %
|
||||
(
|
||||
ModelClass.__name__,
|
||||
ModelClass.__name__,
|
||||
self.__class__.__name__,
|
||||
exc
|
||||
tb
|
||||
)
|
||||
)
|
||||
raise TypeError(msg)
|
||||
|
|
Loading…
Reference in New Issue
Block a user