Skip to content

Commit 02d4129

Browse files
committed
fix: tombstone delete not worked
* with the fix of tombstone not persist on record.commit * the problem is that before the cache was used but that is not more the case, a new state was necessary to know when the tombstone has to be removed
1 parent 074aba4 commit 02d4129

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

invenio_rdm_records/records/systemfields/tombstone.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ def __repr__(self):
149149
class TombstoneField(SystemField):
150150
"""System field for accessing a record's deletion status."""
151151

152+
def mark_to_be_removed(self, instance):
153+
"""Mark to be removed."""
154+
if not hasattr(instance, "_obj_cache"):
155+
instance._obj_cache = {}
156+
instance._obj_cache["remove"] = True
157+
158+
def is_marked_to_be_removed(self, instance):
159+
"""Is marked to be removed."""
160+
if not hasattr(instance, "_obj_cache"):
161+
instance._obj_cache = {}
162+
163+
return instance._obj_cache.get("remove", False)
164+
152165
#
153166
# Data descriptor methods (i.e. attribute access)
154167
#
@@ -165,6 +178,9 @@ def get_obj(self, record, owner=None):
165178
if tombstone is not None:
166179
return tombstone
167180

181+
if self.is_marked_to_be_removed(record):
182+
return None
183+
168184
ts_dict = record.get("tombstone", None)
169185
tombstone = Tombstone(ts_dict) if ts_dict else None
170186
self._set_cache(record, tombstone)
@@ -178,6 +194,7 @@ def set_obj(self, record, value):
178194
"""Set obj."""
179195
if value is None:
180196
tombstone = None
197+
self.mark_to_be_removed(record)
181198
elif isinstance(value, dict):
182199
tombstone = Tombstone(value)
183200
elif isinstance(value, Tombstone):
@@ -187,11 +204,16 @@ def set_obj(self, record, value):
187204

188205
self._set_cache(record, tombstone)
189206

207+
def __delete__(self, record):
208+
"""Remove tombstone."""
209+
self.mark_to_be_removed(record)
210+
self._set_cache(record, None)
211+
190212
def pre_commit(self, record):
191213
"""Dump the configured tombstone before committing the record."""
192214
tombstone = self.get_obj(record)
193-
194215
if tombstone:
195216
record["tombstone"] = tombstone.dump()
196-
else:
217+
218+
if self.is_marked_to_be_removed(record):
197219
record.pop("tombstone", None)

0 commit comments

Comments
 (0)