Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit ee7a50f

Browse files
mahenzonsloria
andauthored
Fix schema with relationship to dump None (#302)
* Fix schema with relationship to dump None * Revert gitignore change (.idea belongs in global gitignore) * Fix test * Update changelog Co-authored-by: Steven Loria <sloria1@gmail.com>
1 parent 9a12a5e commit ee7a50f

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Deprecations/Removals:
99

1010
* Drop support for marshmallow 2, which is now EOL (:pr:`332`).
1111

12+
Bug fixes:
13+
14+
* Fix behavior when serializing ``None`` (:pr:`302`). Thanks :user:`mahenzon`.
15+
1216
Other changes:
1317

1418
* Test against Python 3.8 and 3.9 (:pr:`332`).

marshmallow_jsonapi/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _deserialize(self, value, attr, obj, **kwargs):
244244
# in the request. And we don't have enough control in _serialize
245245
# to prevent their serialization
246246
def serialize(self, attr, obj, accessor=None):
247-
if self.include_resource_linkage or self.include_data:
247+
if obj is None or self.include_resource_linkage or self.include_data:
248248
return super().serialize(attr, obj, accessor)
249249
return self._serialize(None, attr, obj)
250250

tests/test_schema.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def test_dump_none(self):
9696
assert data["data"] is None
9797
assert "links" not in data
9898

99+
def test_schema_with_relationship_processes_none(self):
100+
data = CommentSchema().dump(None)
101+
assert data == {"data": None}
102+
99103
def test_dump_empty_list(self):
100104
data = AuthorSchema(many=True).dump([])
101105

0 commit comments

Comments
 (0)