Skip to content

Commit

Permalink
records: raise on resolving a deleted record
Browse files Browse the repository at this point in the history
Co-authored-by: Zacharias Zacharodimos <[email protected]>
  • Loading branch information
lnielsen and zzacharo committed Oct 19, 2023
1 parent c2de64f commit 97430a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion invenio_records_resources/records/systemfields/pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Record():
"""

from invenio_db import db
from invenio_pidstore.errors import PIDDoesNotExistError
from invenio_pidstore.models import PersistentIdentifier
from invenio_pidstore.resolver import Resolver
from invenio_records.systemfields import (
Expand All @@ -62,7 +63,7 @@ class PIDFieldContext(RelatedModelFieldContext):
Record.pid.session_merge(record)
"""

def resolve(self, pid_value, registered_only=True):
def resolve(self, pid_value, registered_only=True, with_deleted=False):
"""Resolve identifier."""
# Create resolver
resolver = self.field._resolver_cls(
Expand All @@ -74,6 +75,12 @@ def resolve(self, pid_value, registered_only=True):

# Resolve
pid, record = resolver.resolve(pid_value)
# Drafts of published records are soft-deleted and the resolver will
# return a deleted record because the PID is registered (record is
# published). We do not want to return deleted records so we raise
# PID does not exists error.
if not with_deleted and record.is_deleted:
raise PIDDoesNotExistError(self.field._pid_type, pid_value)

# Store pid in cache on record.
self.field._set_cache(record, pid)
Expand Down

0 comments on commit 97430a1

Please sign in to comment.