Job.clean() not called
Deployment Type
Self-hosted
NetBox Version
v4.1.3
Python Version
3.11
Steps to Reproduce
- Create a new
JobRunner. - 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().
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 could you please elaborate on your steps to reproduce above? It is not clear exactly what you're doing. Example code would be helpful.
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:
interval=0violates the field'sMinValueValidator(1).- As no instance is set,
clean()would raise an exception as it doesn't take into accountself.object_typecan beNone. That's a bug related to #17682, #17086 and #17648, but didn't attract attention before, asclean()isn't called by any of the other methods inJob.
As this is not a cause of system jobs (#16971), but the Job model itself, I see this as a separate issue / bug.
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.
@jeremystretch Did you have a chance to review the additional information above?
@alehaa pk, I'll flag this for an owner, unless you'd like to take it?
I can provide a PR. As this is a fix for existing functionality I assume develop is the right branch?
@alehaa great, thanks! And yeah, develop please.