inveniosoftware / invenio-records-rest

Invenio records REST API module.
https://invenio-records-rest.readthedocs.io
MIT License
4 stars 63 forks source link

fields: PersistentIdentifier not (de)serializing as expected #232

Closed slint closed 5 years ago

slint commented 5 years ago

The .schemas.fields.PersistentIdentifier marshmallow field, is assuming a wrong method signature when overriding Field._deserialize and Field._serialize:

# wrong
...
def _deserialize(self, value, attr, context):
    # "context" is actually the original "data" passed to "Schema(...).load"
    # and not the "Schema(context=context).load(...)" (see docs link above)
    pid = context.get('pid')
    return pid.get('pid_value') if pid else missing
...

# correct
def _deserialize(self, value, attr, data):
    pid = self.context.get('pid')
    return pid.get('pid_value') if pid else missing

When addressing this, keep in mind that:

ppanero commented 5 years ago

Fix in https://github.com/inveniosoftware/invenio-records-rest/pull/234