You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found another issue related to support for resource_name. While it works fine for to_representation when my resource has many related resources, i.e.
(here, i could return ownerportal-image instead of portal-image successfully)
it doesn't work when the relationship is the other way around, i.e. my resource is related to only one other resource:
(here, i would have expected ownerimage instead of image)
After debugging a bit, i found that the problem is related to (relations.py, 140)
resource_type = None
root = getattr(self.parent, 'parent', self.parent)
field_name = self.field_name if self.field_name else self.parent.field_name
if getattr(root, 'included_serializers', None) is not None:
In the successful case, self.parent refers to a ManyRelatedField, and self.parent.parent to my serializer.
In the unsuccessful case, self.parent refers to my serializer, while self.parent.parent is Null.
For me, changing the initialization of root to
root = getattr(self.parent, 'parent', self.parent) or self.parent
fixes the problem.
Since i'm a bit unsure if my fix is the right way to go, i thought i'd post this as an issue first to get your feedback. Thanks in advance!
The text was updated successfully, but these errors were encountered:
I found another issue related to support for
resource_name
. While it works fine forto_representation
when my resource has many related resources, i.e.(here, i could return
ownerportal-image
instead ofportal-image
successfully)it doesn't work when the relationship is the other way around, i.e. my resource is related to only one other resource:
(here, i would have expected
ownerimage
instead ofimage
)After debugging a bit, i found that the problem is related to (
relations.py
, 140)In the successful case,
self.parent
refers to aManyRelatedField
, andself.parent.parent
to my serializer.In the unsuccessful case,
self.parent
refers to my serializer, whileself.parent.parent
isNull
.For me, changing the initialization of
root
tofixes the problem.
Since i'm a bit unsure if my fix is the right way to go, i thought i'd post this as an issue first to get your feedback. Thanks in advance!
The text was updated successfully, but these errors were encountered: