Closes #21751: Enable toggling user notifications when executing custom scripts#21923
Closes #21751: Enable toggling user notifications when executing custom scripts#21923jeremystretch wants to merge 5 commits intofeaturefrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude /review |
|
Claude finished @jeremystretch's task in 2m 38s —— View job PR Review: Enable toggling user notifications when executing custom scripts
OverviewThis PR introduces a Code QualityThe implementation is well-structured and follows existing patterns in the codebase. The logic in # core/models/jobs.py:247-256
if self.user and self.notifications != JobNotificationChoices.NOTIFICATION_NEVER:
if (
self.notifications == JobNotificationChoices.NOTIFICATION_ALWAYS or
status != JobStatusChoices.STATUS_COMPLETED
):
Notification(...).save()
Recurring job scheduling in Minor Observations1. Migration missing
field=models.CharField(default='always', max_length=30),Auto-generated migrations include 2.
_notifications = forms.ChoiceField(
required=False,
choices=JobNotificationChoices,
...
)The choices don't include a blank option, so a browser-rendered dropdown will always have one of the three valid values selected. But 3. Class-level
notifications = serializers.ChoiceField(
choices=JobNotificationChoices,
required=False,
default=JobNotificationChoices.NOTIFICATION_ALWAYS,
)The 4. In TestsThe three test cases in DocumentationThe SummaryThis is a clean, well-executed implementation. The main actionable item is the migration (point 1). Points 2–4 are minor and may be acceptable as-is. The core logic, API integration, and tests are solid. |
|
arthanson
left a comment
There was a problem hiding this comment.
If you run it from the scripts list page:
Get error:
Traceback (most recent call last):
File "/Users/ahanson/dev/work/netbox/venv/lib/python3.14/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/Users/ahanson/dev/work/netbox/venv/lib/python3.14/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/ahanson/dev/work/netbox/venv/lib/python3.14/site-packages/django/views/generic/base.py", line 105, in view
return self.dispatch(request, *args, **kwargs)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahanson/dev/work/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
return super().dispatch(request, *args, **kwargs)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 149, in dispatch
return super().dispatch(request, *args, **kwargs)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahanson/dev/work/netbox/netbox/utilities/views.py", line 48, in dispatch
return super().dispatch(request, *args, **kwargs)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahanson/dev/work/netbox/venv/lib/python3.14/site-packages/django/views/generic/base.py", line 144, in dispatch
return handler(request, *args, **kwargs)
File "/Users/ahanson/dev/work/netbox/netbox/extras/views.py", line 1705, in post
job = ScriptJob.enqueue(
instance=script,
...<7 lines>...
commit=form.cleaned_data.pop('_commit'),
)
File "/Users/ahanson/dev/work/netbox/netbox/netbox/jobs.py", line 174, in enqueue
return Job.enqueue(cls.handle, name=name, *args, **kwargs)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahanson/dev/work/netbox/netbox/core/models/jobs.py", line 320, in enqueue
job.full_clean()
~~~~~~~~~~~~~~^^
File "/Users/ahanson/dev/work/netbox/venv/lib/python3.14/site-packages/django/db/models/base.py", line 1679, in full_clean
raise ValidationError(errors)
django.core.exceptions.ValidationError: {'notifications': ['This field cannot be blank.']}
Closes: #21751
notificationsChoiceField on the Job modelJob.terminate()to send notifications conditionallynotifications_defaultMeta option for custom scripts