From de58d0eccae5553dca70946386ccb3201d605189 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 28 Apr 2017 14:26:17 -0400 Subject: [PATCH] Fixes #1114: Suppress OSError when attempting to access a delete image attachment --- netbox/extras/models.py | 10 ++++++++++ netbox/templates/inc/image_attachments.html | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/netbox/extras/models.py b/netbox/extras/models.py index 485448336..06ed07b85 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -422,6 +422,16 @@ class ImageAttachment(models.Model): # before the request finishes. (For example, to display a message indicating the ImageAttachment was deleted.) self.image.name = _name + @property + def size(self): + """ + Wrapper around `image.size` to suppress an OSError in case the file is inaccessible. + """ + try: + return self.image.size + except OSError: + return None + # # User actions diff --git a/netbox/templates/inc/image_attachments.html b/netbox/templates/inc/image_attachments.html index 0f922f3c6..d467eb414 100644 --- a/netbox/templates/inc/image_attachments.html +++ b/netbox/templates/inc/image_attachments.html @@ -7,12 +7,12 @@ {% for attachment in images %} - + {{ attachment }} - {{ attachment.image.size|filesizeformat }} + {{ attachment.size|filesizeformat }} {{ attachment.created }} {% if perms.extras.change_imageattachment %}