From fdf4fe4263b8bd2981c47ee2d47599b5c43bd87c Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 6 Nov 2025 16:57:30 -0800 Subject: [PATCH 1/2] 20465 fix script re-upload --- netbox/extras/forms/scripts.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/netbox/extras/forms/scripts.py b/netbox/extras/forms/scripts.py index 5f9820b44e2..336da2a570a 100644 --- a/netbox/extras/forms/scripts.py +++ b/netbox/extras/forms/scripts.py @@ -69,9 +69,18 @@ def save(self, *args, **kwargs): storage = storages.create_storage(storages.backends["scripts"]) filename = self.cleaned_data['upload_file'].name - self.instance.file_path = filename data = self.cleaned_data['upload_file'] - storage.save(filename, data) + + # If editing an existing file, delete the old one first to avoid random suffix + if self.instance.pk and self.instance.file_path: + try: + storage.delete(self.instance.file_path) + except FileNotFoundError: + pass + + # Save the new file and capture the actual filename + actual_filename = storage.save(filename, data) + self.instance.file_path = actual_filename # need to skip ManagedFileForm save method return super(ManagedFileForm, self).save(*args, **kwargs) From 6367530581c742f17c8f611bb9755e712e9471db Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 6 Nov 2025 17:01:55 -0800 Subject: [PATCH 2/2] 20465 fix script re-upload --- netbox/extras/forms/scripts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/extras/forms/scripts.py b/netbox/extras/forms/scripts.py index 336da2a570a..52969a8dc0c 100644 --- a/netbox/extras/forms/scripts.py +++ b/netbox/extras/forms/scripts.py @@ -79,8 +79,8 @@ def save(self, *args, **kwargs): pass # Save the new file and capture the actual filename - actual_filename = storage.save(filename, data) - self.instance.file_path = actual_filename + self.instance.file_path = filename + storage.save(filename, data) # need to skip ManagedFileForm save method return super(ManagedFileForm, self).save(*args, **kwargs)