Skip to content

Commit

Permalink
[#12110] Clean up some deprecation messages (#12133)
Browse files Browse the repository at this point in the history
  • Loading branch information
etj authored Apr 4, 2024
1 parent b295c22 commit 6ce7f86
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
26 changes: 24 additions & 2 deletions geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion geonode/people/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions geonode/resource/api/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
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"
Expand Down

0 comments on commit 6ce7f86

Please sign in to comment.