From 6d47946b1b941874049ec5a4d8a25933fac65aad Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Thu, 4 Apr 2019 11:47:23 +0200 Subject: [PATCH] Fix for exception in /open-movies When extension_props.cloud.poster was set to empty string, we would try to get file anyway and we would set the has_poster has_poster convenience attribute to true. This would lead to an exception when trying to access the poster file object in the template. --- cloud/routes.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cloud/routes.py b/cloud/routes.py index 9cc0594..5818721 100644 --- a/cloud/routes.py +++ b/cloud/routes.py @@ -207,17 +207,22 @@ def open_projects(): 'sort': '-_created', }, api=api) for project in projects._items: - # Attach poster file (ensure the extension_props.cloud.poster attributes exists) - if 'extension_props' not in project: + # Attach poster file (ensure the extension_props.cloud.poster + # attributes exists) + try: + # If the attribute exists, but is None, continue + if not project['extension_props'][EXTENSION_NAME]['poster']: + continue + # Fetch the file and embed it in the document + project.extension_props.cloud.poster = get_file( + project.extension_props.cloud.poster, api=api) + # Add convenience attribute that specifies the presence of the + # poster file + project.has_poster = True + # If there was a key error because one of the nested attributes is + # missing, + except KeyError: continue - if EXTENSION_NAME not in project['extension_props']: - continue - if 'poster' not in project['extension_props'][EXTENSION_NAME]: - continue - project.extension_props.cloud.poster = get_file( - project.extension_props.cloud.poster, api=api) - # Add convenience attribute that specifies the presence of the poster file - project.has_poster = True return render_template( 'films.html',