Skip to content

Commit 275eaf2

Browse files
committed
fix(chore): RemovedInMarshmallow4Warning
* The `context` parameter is deprecated and will be removed in marshmallow 4.0. Use `contextvars.ContextVar` to pass context instead. * moved record_dict from self.context to class constructor
1 parent 4b6f165 commit 275eaf2

File tree

1 file changed

+9
-3
lines changed
  • invenio_rdm_records/resources/serializers/signposting

1 file changed

+9
-3
lines changed

invenio_rdm_records/resources/serializers/signposting/schema.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# Copyright (C) 2023 Northwestern University.
44
# Copyright (C) 2024-2025 CERN.
5+
# Copyright (C) 2025 Graz University of Technology.
56
#
67
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
78
# it under the terms of the MIT License; see LICENSE file for more details.
@@ -198,9 +199,14 @@ class ContentResourceSchema(Schema):
198199
anchor = fields.Method(serialize="serialize_anchor")
199200
collection = fields.Method(serialize="serialize_collection")
200201

202+
def __init__(self, record_dict, **kwargs):
203+
"""Construct ContentResourceSchema."""
204+
super().__init__(**kwargs)
205+
self.record_dict = record_dict
206+
201207
def serialize_anchor(self, obj, **kwargs):
202208
"""Serialize to download url."""
203-
pid_value = self.context["record_dict"]["id"]
209+
pid_value = self.record_dict["id"]
204210
return invenio_url_for(
205211
"invenio_app_rdm_records.record_file_download",
206212
pid_value=pid_value,
@@ -211,7 +217,7 @@ def serialize_collection(self, obj, **kwargs):
211217
"""Serialize to record landing page url."""
212218
return [
213219
{
214-
"href": self.context["record_dict"]["links"]["self_html"],
220+
"href": self.record_dict["links"]["self_html"],
215221
"type": "text/html",
216222
}
217223
]
@@ -254,7 +260,7 @@ def serialize_linkset(self, obj, **kwargs):
254260
"""Serialize linkset."""
255261
result = [LandingPageLvl2Schema().dump(obj)]
256262

257-
content_resource_schema = ContentResourceSchema(context={"record_dict": obj})
263+
content_resource_schema = ContentResourceSchema(record_dict=obj)
258264
result += [
259265
content_resource_schema.dump(entry)
260266
for entry in obj.get("files", {}).get("entries", {}).values()

0 commit comments

Comments
 (0)