Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #4 where an ErrorDetail string subclass raises an error. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rest_framework_yaml/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@
except ImportError:
ReturnDict = None
ReturnList = None

try:
# Note: ErrorDetail was introduced in DRF 3.5.0
from rest_framework.exceptions import ErrorDetail
except ImportError:
ErrorDetail = None
9 changes: 8 additions & 1 deletion rest_framework_yaml/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Helper classes for parsers.
"""
from __future__ import unicode_literals

import decimal
import types

from django.utils import six

from .compat import (
yaml, yaml_represent_text, Hyperlink, OrderedDict, ReturnDict, ReturnList
yaml, yaml_represent_text, Hyperlink, OrderedDict, ReturnDict, ReturnList, ErrorDetail
)


Expand Down Expand Up @@ -80,3 +81,9 @@ def represent_mapping(self, tag, mapping, flow_style=None):
ReturnList,
yaml.representer.SafeRepresenter.represent_list
)

if ErrorDetail:
SafeDumper.add_representer(
ErrorDetail,
yaml_represent_text
)