Skip to content

Commit 8820cac

Browse files
Merge pull request #7820 from kkthxbye-code/script-reload
Fix #7803: Clear sys.modules cache when reloading scripts
2 parents ada911c + 9458521 commit 8820cac

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

netbox/extras/scripts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import pkgutil
6+
import sys
67
import traceback
78
from collections import OrderedDict
89

@@ -477,6 +478,10 @@ def get_scripts(use_names=False):
477478
# Iterate through all modules within the reports path. These are the user-created files in which reports are
478479
# defined.
479480
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
481+
# Remove cached module to ensure consistency with filesystem
482+
if module_name in sys.modules:
483+
del sys.modules[module_name]
484+
480485
module = importer.find_module(module_name).load_module(module_name)
481486
if use_names and hasattr(module, 'name'):
482487
module_name = module.name

0 commit comments

Comments
 (0)