From deb04500c5ffd3d8e3e679f92d4d1aed7da4cdb2 Mon Sep 17 00:00:00 2001 From: Jens Gutermuth Date: Mon, 23 Mar 2015 03:30:13 +0100 Subject: [PATCH] Only use prefetched thumbnails if there are there The optimization broke image uploading, this fixes it again. --- pinry/core/api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pinry/core/api.py b/pinry/core/api.py index 6cfa069..958d59c 100644 --- a/pinry/core/api.py +++ b/pinry/core/api.py @@ -60,10 +60,13 @@ class UserResource(ModelResource): def filter_generator_for(size): def wrapped_func(bundle, **kwargs): - for thumbnail in bundle.obj._prefetched_objects_cache['thumbnail']: - if thumbnail.size == size: - return thumbnail - raise ObjectDoesNotExist() + if hasattr(bundle.obj, '_prefetched_objects_cache') and 'thumbnail' in bundle.obj._prefetched_objects_cache: + for thumbnail in bundle.obj._prefetched_objects_cache['thumbnail']: + if thumbnail.size == size: + return thumbnail + raise ObjectDoesNotExist() + else: + return bundle.obj.get_by_size(size) return wrapped_func