Skip to content

Commit bb73fab

Browse files
committed
Fixes #19529: Properly find scripts managed by ScriptFileSystemStorage
ScriptFileSystemStorage was introduced in #18896 and stores a full path in Script.file_path. This fix handles looking for scripts by relative path as well as full path.
1 parent b3d318c commit bb73fab

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

netbox/extras/scripts.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.conf import settings
1010
from django.core.files.storage import storages
1111
from django.core.validators import RegexValidator
12+
from django.db.models import Q
1213
from django.utils import timezone
1314
from django.utils.functional import classproperty
1415
from django.utils.translation import gettext as _
@@ -646,6 +647,10 @@ def is_variable(obj):
646647

647648

648649
def get_module_and_script(module_name, script_name):
649-
module = ScriptModule.objects.get(file_path=f'{module_name}.py')
650+
path = f'{module_name}.py'
651+
module = ScriptModule.objects.get(
652+
Q(file_path=path) |
653+
Q(file_path=os.path.join(settings.SCRIPTS_ROOT, path))
654+
)
650655
script = module.scripts.get(name=script_name)
651656
return module, script

0 commit comments

Comments
 (0)