Elastic: handle pictures without variations or project ID

This happens on old file documents.
This commit is contained in:
Sybren A. Stüvel 2018-01-05 14:20:52 +01:00
parent 2ca960a73f
commit 4381ed6671

View File

@ -41,14 +41,26 @@ def _handle_picture(node: dict, to_index: dict):
picture = files_collection.find_one(lookup)
img_variation_t = next(
(item for item in picture['variations']
(item for item in picture.get('variations', [])
if item['size'] == 't'), None)
if img_variation_t:
if not img_variation_t:
return
try:
pic_pid = picture['project']
except KeyError:
if picture.get('backend') != 'pillar':
# We know for sure that locally saved images don't need regeneration,
# so don't bother warning about that.
log.warning('Picture %s has no project ID, unable to regenerate link',
picture['_id'])
to_index['picture'] = img_variation_t['link']
else:
to_index['picture'] = generate_link(
picture['backend'],
img_variation_t['file_path'],
project_id=str(picture['project']),
project_id=str(pic_pid),
is_public=True)