changeset 3202:2e892f9f54f6

plugin attachment: remove "path" from attachment once used: "path" refers to a local path of a file, we don't want to store it in database as the file may be in a temporary location, or even be a temporary file. So once the file has been uploaded, we remove it.
author Goffi <goffi@goffi.org>
date Fri, 06 Mar 2020 18:19:03 +0100
parents 439e2f88c3a9
children fee8e33e2b3f
files sat/plugins/plugin_misc_attach.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_attach.py	Sun Mar 01 18:48:06 2020 +0100
+++ b/sat/plugins/plugin_misc_attach.py	Fri Mar 06 18:19:03 2020 +0100
@@ -59,15 +59,19 @@
 
         for attachment in attachments:
             try:
-                path = Path(attachment["path"])
+                # we pop path because we don't want it to be stored, as the image can be
+                # only in a temporary location
+                path = Path(attachment.pop("path"))
             except KeyError:
                 log.warning("no path in attachment: {attachment}")
                 to_delete.append(attachment)
                 continue
 
             if "url" in attachment:
-                log.warning("invalid attachment: unknown URL")
-                to_delete.append(attachment)
+                url = attachment.pop('url')
+                log.warning(
+                    f"unexpected URL in attachment: {url!r}\nattachment: {attachment}"
+                )
 
             try:
                 name = attachment["name"]