Job.clean() not called #10324

Closed
opened 2025-12-29 21:29:59 +01:00 by adam · 8 comments
Owner

Originally created by @alehaa on GitHub (Oct 7, 2024).

Originally assigned to: @alehaa on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.1.3

Python Version

3.11

Steps to Reproduce

  1. Create a new JobRunner.
  2. Schedule the job runner without with enqueue(interval=0).

Expected Behavior

Getting a ValidationError:

django.core.exceptions.ValidationError: {
  '__all__': [
    'Jobs cannot be assigned to this object type (None).'
  ]
}

Observed Behavior

Nothing happens, as neither Job.enqueue(), Job.start() nor Job.terminate() trigger Job.clean().

Originally created by @alehaa on GitHub (Oct 7, 2024). Originally assigned to: @alehaa on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.1.3 ### Python Version 3.11 ### Steps to Reproduce 1. Create a new `JobRunner`. 2. Schedule the job runner without with `enqueue(interval=0)`. ### Expected Behavior Getting a `ValidationError`: ```Python django.core.exceptions.ValidationError: { '__all__': [ 'Jobs cannot be assigned to this object type (None).' ] } ``` ### Observed Behavior Nothing happens, as neither `Job.enqueue()`, `Job.start()` nor `Job.terminate()` trigger `Job.clean()`.
adam added the type: bugstatus: acceptednetboxseverity: low labels 2025-12-29 21:29:59 +01:00
adam closed this issue 2025-12-29 21:29:59 +01:00
Author
Owner

@alehaa commented on GitHub (Oct 7, 2024):

This error occured during testing of similar issues, as Job.clean() (like #17682, #17086 and #17648) assumes the object_type field is not None. If its decided Job should call clean(), this should be fixed as well (could happen in conjunction with #17682). Otherwise the method could be removed IMHO.

@alehaa commented on GitHub (Oct 7, 2024): This error occured during testing of similar issues, as `Job.clean()` (like #17682, #17086 and #17648) assumes the `object_type` field is not `None`. If its decided `Job` should call `clean()`, this should be fixed as well (could happen in conjunction with #17682). Otherwise the method could be removed IMHO.
Author
Owner

@jeremystretch commented on GitHub (Oct 7, 2024):

@alehaa could you please elaborate on your steps to reproduce above? It is not clear exactly what you're doing. Example code would be helpful.

@jeremystretch commented on GitHub (Oct 7, 2024): @alehaa could you please elaborate on your steps to reproduce above? It is not clear exactly what you're doing. Example code would be helpful.
Author
Owner

@alehaa commented on GitHub (Oct 7, 2024):

During the implementation of #16971, I tested whether NetBox would raise exceptions on incorrectly configured jobs, and whether separate tests needed to be added to the system job registration. I added this (abbreviated) code to NetBox:

class SampleJob(JobRunner):
    def run(self, *args, **kwargs):
        pass

SampleJob.enqueue_once(interval=0)

The job can be scheduled without error. However, this should fail for two reasons:

  1. interval=0 violates the field's MinValueValidator(1).
  2. As no instance is set, clean() would raise an exception as it doesn't take into account self.object_type can be None. That's a bug related to #17682, #17086 and #17648, but didn't attract attention before, as clean() isn't called by any of the other methods in Job.

As this is not a cause of system jobs (#16971), but the Job model itself, I see this as a separate issue / bug.

@alehaa commented on GitHub (Oct 7, 2024): During the implementation of #16971, I tested whether NetBox would raise exceptions on incorrectly configured jobs, and whether separate tests needed to be added to the system job registration. I added this (abbreviated) code to NetBox: ```Python class SampleJob(JobRunner): def run(self, *args, **kwargs): pass SampleJob.enqueue_once(interval=0) ``` The job can be scheduled without error. However, this should fail for two reasons: 1. `interval=0` violates the field's `MinValueValidator(1)`. 2. As no instance is set, `clean()` would raise an exception as it doesn't take into account `self.object_type` can be `None`. That's a bug related to #17682, #17086 and #17648, but didn't attract attention before, as `clean()` isn't called by any of the other methods in `Job`. As this is not a cause of system jobs (#16971), but the `Job` model itself, I see this as a separate issue / bug.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 15, 2024):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Oct 15, 2024): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@alehaa commented on GitHub (Oct 15, 2024):

@jeremystretch Did you have a chance to review the additional information above?

@alehaa commented on GitHub (Oct 15, 2024): @jeremystretch Did you have a chance to review the additional information above?
Author
Owner

@jeremystretch commented on GitHub (Oct 22, 2024):

@alehaa pk, I'll flag this for an owner, unless you'd like to take it?

@jeremystretch commented on GitHub (Oct 22, 2024): @alehaa pk, I'll flag this for an owner, unless you'd like to take it?
Author
Owner

@alehaa commented on GitHub (Oct 22, 2024):

I can provide a PR. As this is a fix for existing functionality I assume develop is the right branch?

@alehaa commented on GitHub (Oct 22, 2024): I can provide a PR. As this is a fix for existing functionality I assume `develop` is the right branch?
Author
Owner

@jeremystretch commented on GitHub (Oct 22, 2024):

@alehaa great, thanks! And yeah, develop please.

@jeremystretch commented on GitHub (Oct 22, 2024): @alehaa great, thanks! And yeah, `develop` please.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10324