-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Deployment Type
Self-hosted
NetBox Version
v4.2.9
Python Version
3.12
Steps to Reproduce
When a script class inherits required fields (e.g. via a shared mixin), but those fields are not listed in its Meta.fieldsets
, the UI form fails validation silently. The form is not rendered properly, the user sees no error, and the script cannot be executed—making the issue hard to debug.
Use case
- Common logic and script variables are reused via mixins.
- Some scripts intentionally exclude certain inherited fields from the UI by omitting them from
fieldsets
. - However, if an inherited field is defined as
required=True
, form validation fails even if that field is hidden, and no feedback is presented to the user.
Script code example:
Base mixin (note: bar
field is required by default)
class MyScriptMixin:
class Meta:
commit_default = False
fieldsets = (
(
"Section Foo",
(
"bar",
),
),
(
"Logging",
("debug_mode",),
),
)
bar = IntegerVar(
0,
30,
description="Bar Integer Field",
default=30,
)
Actual NetBox Script
class MyScript(MyScriptMixin, Script):
class Meta:
name = "My script"
description = "My script descpription"
commit_default = False
fieldsets = (
(
"Limit",
(
"vrf_selector",
"tag_selector",
),
),
(
"Logging",
("debug_mode",),
),
)
vrf_selector = MultiObjectVar(
label="VRF selector",
description="Limit script to only selected VRFs",
model=VRF,
required=False,
)
tag_selector = MultiObjectVar(
label="Tag selector",
description="Limit script to only IP addresses tagged with selected tags",
model=Tag,
required=False,
)
Expected Behavior
Form validation errors should be visible in the UI (e.g. via Django messages or inline form field errors).
Observed Behavior
When clicking "Run Script", the page is simply reloaded with no visible error or feedback to the user. The script form appears to reset, and no indication is given that validation failed. This creates confusion, as it appears that the script did not run but provides no explanation why.
I would suggest adding the following condition at this line to improve form error visibility:
elif not form.is_valid():
messages.error(request, form.errors.as_text())
This would provide immediate feedback when a script form fails validation, rather than silently reloading the page without explanation.
Would you be open to a PR implementing this?
Current behavior:
Screencast.from.14-07-2025.14.38.07.webm
Expected: