From 9cb2c78e3483508202907738b38a2a05a6b7c2ec Mon Sep 17 00:00:00 2001 From: bctiemann Date: Wed, 15 Oct 2025 14:09:22 -0400 Subject: [PATCH] Init storage at class level of BaseScript instead of in findsource function (#20575) --- netbox/extras/scripts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index a14eba556..4855735e2 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -329,6 +329,9 @@ class BaseScript: # Declare the placeholder for the current request self.request = None + # Initiate the storage backend (local, S3, etc) as a class attr + self.storage = storages.create_storage(storages.backends["scripts"]) + # Compile test methods and initialize results skeleton for method in dir(self): if method.startswith('test_') and callable(getattr(self, method)): @@ -394,8 +397,7 @@ class BaseScript: return inspect.getfile(self.__class__) def findsource(self, object): - storage = storages.create_storage(storages.backends["scripts"]) - with storage.open(os.path.basename(self.filename), 'r') as f: + with self.storage.open(os.path.basename(self.filename), 'r') as f: data = f.read() # Break the source code into lines