diff --git a/geonode/base/api/serializers.py b/geonode/base/api/serializers.py index 115e3b8a250..5aa9e42d7fc 100644 --- a/geonode/base/api/serializers.py +++ b/geonode/base/api/serializers.py @@ -87,8 +87,16 @@ def to_representation(self, instance): path = f"{path}/" url = urljoin(path, str(instance.pk)) data["link"] = build_absolute_uri(url) + + parents = [] + parent = self.parent + while parent: + parents.append(type(parent).__name__) + parent = parent.parent + logger.warning( - f"Deprecated: BaseDynamicModelSerializer should be replaced with proper Field - Root: {type(self).__name__}" + f"Deprecated: BaseDynamicModelSerializer should be replaced with proper Field" + f" - Parents: {parents} Root: {type(self).__name__}" ) except (TypeError, NoReverseMatch) as e: logger.exception(e) @@ -331,13 +339,27 @@ def get_attribute(self, instance): class AutoLinkField(DynamicComputedField): def get_attribute(self, instance): + parents = [] + parent = self.parent + while parent: + parents.append(type(parent).__name__) + parent = parent.parent + + logger.debug( + f"AutoLinkField reading Meta from first parent - Parents: {parents} root: {type(self.root).__name__}" + ) + try: - path = reverse(self.root.Meta.view_name) + path = reverse(self.parent.Meta.view_name) if not path.endswith("/"): path = f"{path}/" url = urljoin(path, str(instance.pk)) return build_absolute_uri(url) + except AttributeError as e: + logger.exception(f"Parents: {parents} root: {type(self.root).__name__}", exc_info=e) + return None + except Exception as e: logger.exception(e) return None diff --git a/geonode/people/api/serializers.py b/geonode/people/api/serializers.py index b4473a06ccd..141f14b8e42 100644 --- a/geonode/people/api/serializers.py +++ b/geonode/people/api/serializers.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) -class UserSerializer(base_serializers.BaseDynamicModelSerializer): +class UserSerializer(base_serializers.DynamicModelSerializer): link = base_serializers.AutoLinkField(read_only=True) diff --git a/geonode/resource/api/serializer.py b/geonode/resource/api/serializer.py index 9c373574b7c..05336c3b0ea 100644 --- a/geonode/resource/api/serializer.py +++ b/geonode/resource/api/serializer.py @@ -16,11 +16,16 @@ # along with this program. If not, see . # ######################################################################### -from geonode.base.api.serializers import BaseDynamicModelSerializer +from dynamic_rest.serializers import DynamicModelSerializer + +from geonode.base.api.serializers import AutoLinkField from geonode.resource.models import ExecutionRequest -class ExecutionRequestSerializer(BaseDynamicModelSerializer): +class ExecutionRequestSerializer(DynamicModelSerializer): + + link = AutoLinkField(read_only=True) + class Meta: model = ExecutionRequest name = "request"