Skip to content

Commit

Permalink
Upstream PR 19: Gracefully Proceed on Sort Error (TypeError)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan6419846 committed May 26, 2023
1 parent fe79fc6 commit bf54f60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

strategy:
matrix:
platform: ["ubuntu-latest"]
platform: ["ubuntu-20.04"]
python-version: ["3.6", "3.7", "3.8"]

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
Expand All @@ -44,8 +44,8 @@
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: "3.8"

Expand All @@ -67,8 +67,8 @@
runs-on: "${{ matrix.os }}"

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: "3.8"
- name: "Install in dev mode"
Expand Down
5 changes: 4 additions & 1 deletion rest_framework_yaml/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def represent_mapping(self, tag, mapping, flow_style=None):
if hasattr(mapping, "items"):
mapping = list(mapping.items())
if not isinstance(mapping, OrderedDict):
mapping.sort()
try:
mapping.sort()
except TypeError:
pass
for item_key, item_value in mapping:
item_value = self._fix_value_before_representation(item_value)
node_key = self.represent_data(item_key)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ def test_proper_encoding(self):
renderer = YAMLRenderer()
content = renderer.render(obj, "application/yaml")
self.assertEqual(content.strip(), _yaml_repr.encode("utf-8"))

def test_render_none_type(self):
"""
Test YAML rendering with None type
"""
_yaml_repr = "foo:\n- bar\n- baz\nnull:\n- null\n"

obj = {"foo": ["bar", "baz"], None: [None]}

renderer = YAMLRenderer()
content = renderer.render(obj, "application/yaml")

self.assertEqual(_yaml_repr, content.decode("utf-8"))

0 comments on commit bf54f60

Please sign in to comment.