From b71722160595e42900a3393be329fb4287cd5f41 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 10 Dec 2024 16:09:01 +0100 Subject: [PATCH] fix(relations): only serialize if there is an object --- apis_core/relations/serializers.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apis_core/relations/serializers.py b/apis_core/relations/serializers.py index 04cd29bd5..5bb11cca8 100644 --- a/apis_core/relations/serializers.py +++ b/apis_core/relations/serializers.py @@ -13,10 +13,12 @@ class Meta: @extend_schema_field(SimpleObjectSerializer()) def get_subj(self, obj): - serializer = serializer_factory(type(obj.subj), SimpleObjectSerializer) - return serializer(obj.subj, context={"request": self.context["request"]}).data + if obj.subj: + serializer = serializer_factory(type(obj.subj), SimpleObjectSerializer) + return serializer(obj.subj, context={"request": self.context["request"]}).data @extend_schema_field(SimpleObjectSerializer()) def get_obj(self, obj): - serializer = serializer_factory(type(obj.obj), SimpleObjectSerializer) - return serializer(obj.obj, context={"request": self.context["request"]}).data + if obj.obj: + serializer = serializer_factory(type(obj.obj), SimpleObjectSerializer) + return serializer(obj.obj, context={"request": self.context["request"]}).data