Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Override to_representation instead of setting default (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb authored May 3, 2022
1 parent 9de6691 commit 6df9ed4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/catalog/api/serializers/media_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class MediaSerializer(serializers.Serializer):
)

tags = TagSerializer(
default=[],
allow_null=True,
many=True,
help_text="Tags with detailed metadata, such as accuracy.",
)
Expand Down Expand Up @@ -403,6 +403,12 @@ def validate_creator_url(self, value):
def validate_foreign_landing_url(self, value):
return _add_protocol(value)

def to_representation(self, *args, **kwargs):
repr = super().to_representation(*args, **kwargs)
if repr["tags"] is None:
repr["tags"] = [] # ``tags`` should always be a list, even if empty
return repr


class MediaSearchSerializer(serializers.Serializer):
"""
Expand Down

0 comments on commit 6df9ed4

Please sign in to comment.