Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a background job is scheduled without an instance, delete() on the job model will throw exceptions #17648

Closed
DanSheps opened this issue Sep 30, 2024 · 3 comments · Fixed by #17657
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@DanSheps
Copy link
Member

Deployment Type

Self-hosted

NetBox Version

v4.1.2

Python Version

3.12

Steps to Reproduce

  1. Create a JobRunner class
  2. Do not assign an object to the job instance
  3. Add the JobRunner.enqueue_once to the ready() of a plugin

Expected Behavior

NetBox will function normally

Observed Behavior

AttributeError is raised in Job.delete()

@DanSheps DanSheps added type: bug A confirmed report of unexpected behavior in the application status: needs triage This issue is awaiting triage by a maintainer labels Sep 30, 2024
@alehaa
Copy link
Contributor

alehaa commented Sep 30, 2024

I believe this is because delete() doesn't check if object_type is None.

rq_queue_name = get_config().QUEUE_MAPPINGS.get(self.object_type.model, RQ_QUEUE_DEFAULT)

In enqueue() this is handled by:

rq_queue_name = get_queue_for_model(object_type.model if object_type else None)

I suggest using the same lookup in both instances and add to add a test checking jobs actually can be deleted. If this is accepted, I volunteer for a PR.

@DanSheps DanSheps added status: accepted This issue has been accepted for implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: needs triage This issue is awaiting triage by a maintainer labels Sep 30, 2024
@DanSheps DanSheps self-assigned this Sep 30, 2024
@DanSheps
Copy link
Member Author

Yup, I knew the problem, but thanks for pointing out the get_queue_for_model method.

@alehaa
Copy link
Contributor

alehaa commented Oct 6, 2024

It seems that deleting jobs is already covered by a test case (test_enqueue_once_twice_different_schedule_at internally triggers a job.delete()). However, this only applies to jobs with an instance set. I'll add tests for jobs without instances during implementation of #16971, so this will be covered as well.

jeremystretch added a commit that referenced this issue Oct 7, 2024
…_type specified (#17657)

* Fixes: #17648 - Fix exception thrown in `Job.delete()` when no object_type specified

* Remove unrelated fix

* Change back elif to if

* Remove unused imports

---------

Co-authored-by: Jeremy Stretch <[email protected]>
bctiemann pushed a commit that referenced this issue Oct 11, 2024
…_type specified (#17657)

* Fixes: #17648 - Fix exception thrown in `Job.delete()` when no object_type specified

* Remove unrelated fix

* Change back elif to if

* Remove unused imports

---------

Co-authored-by: Jeremy Stretch <[email protected]>
bctiemann pushed a commit that referenced this issue Oct 11, 2024
jeremystretch added a commit to alehaa/netbox that referenced this issue Oct 11, 2024
…` when no object_type specified (netbox-community#17657)

* Fixes: netbox-community#17648 - Fix exception thrown in `Job.delete()` when no object_type specified

* Remove unrelated fix

* Change back elif to if

* Remove unused imports

---------

Co-authored-by: Jeremy Stretch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
2 participants