Orphan finder: also interpret 24-char hex strings as ObjectIDs

This is necessary as some dynamic node properties have ObjectIDs saved
as strings.
This commit is contained in:
2017-09-14 17:43:23 +02:00
parent d4facbf2e3
commit 54bb506e10
2 changed files with 26 additions and 1 deletions

View File

@@ -553,6 +553,7 @@ def _find_orphan_files() -> typing.Set[bson.ObjectId]:
Returns an iterable of all orphan file IDs.
"""
from pillar.api.utils import str2id
log.debug('Finding orphan files')
@@ -570,6 +571,12 @@ def _find_orphan_files() -> typing.Set[bson.ObjectId]:
def find_object_ids(something: typing.Any) -> typing.Iterable[bson.ObjectId]:
if isinstance(something, bson.ObjectId):
yield something
elif isinstance(something, str) and len(something) == 24:
try:
yield bson.ObjectId(something)
except (bson.objectid.InvalidId, TypeError):
# It apparently wasn't an ObjectID after all.
pass
elif isinstance(something, (list, set, tuple)):
for item in something:
yield from find_object_ids(item)