From 39d7ca42fb91b5a2f42512173051f2c382c8b87b Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 12 Jun 2025 07:56:51 -0700 Subject: [PATCH] 19529 fix custom script path --- .../migrations/0129_fix_script_paths.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 netbox/extras/migrations/0129_fix_script_paths.py diff --git a/netbox/extras/migrations/0129_fix_script_paths.py b/netbox/extras/migrations/0129_fix_script_paths.py new file mode 100644 index 000000000..4c016178e --- /dev/null +++ b/netbox/extras/migrations/0129_fix_script_paths.py @@ -0,0 +1,31 @@ +from django.conf import settings +from django.core.files.storage import storages +from django.db import migrations + +from extras.storage import ScriptFileSystemStorage + + +def fix_script_paths(apps, schema_editor): + """ + Fix script paths for scripts that had incorrect path from NB 4.3. + """ + storage = storages.create_storage(storages.backends["scripts"]) + if not isinstance(storage, ScriptFileSystemStorage): + return + + ScriptModule = apps.get_model('extras', 'ScriptModule') + for script in ScriptModule.objects.all(): + if script.file_path.startswith(settings.SCRIPTS_ROOT): + script.file_path = script.file_path[len(settings.SCRIPTS_ROOT):] + script.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0128_tableconfig'), + ] + + operations = [ + migrations.RunPython(code=fix_script_paths, reverse_code=migrations.RunPython.noop), + ]