From 428033da0fa1f1d82977d93190a2b1c9f8bf5305 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 4 May 2021 14:15:30 +0200 Subject: [PATCH] pwa: use icon file basename during import (#53720) Django 2.2.21 introduced the validation of FieldFile.save() name argument, which cannot contain a path separator anymore. To use the received FileField value as a base filename, we must apply os.path.basename() on it first. ref. https://docs.djangoproject.com/en/3.2/releases/2.2.21/ --- combo/apps/pwa/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/combo/apps/pwa/models.py b/combo/apps/pwa/models.py index 94bf1809..de606045 100644 --- a/combo/apps/pwa/models.py +++ b/combo/apps/pwa/models.py @@ -18,6 +18,7 @@ import base64 import json +import os from django.conf import settings from django.core import serializers @@ -188,7 +189,7 @@ class PwaNavigationEntry(models.Model): decoded_icon = base64.decodebytes(force_bytes(json_entry['icon:base64'])) if not default_storage.exists(entry.object.icon.name) or entry.object.icon.read() != decoded_icon: # save new file - entry.object.icon.save(entry.object.icon.name, ContentFile(decoded_icon)) + entry.object.icon.save(os.path.basename(entry.object.icon.name), ContentFile(decoded_icon)) class PushSubscription(models.Model):