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

Open
DanSheps opened this issue Sep 30, 2024 · 2 comments · May be 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.

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