[PR #18062] [MERGED] Fixes: #17950 - Handle InvalidJobOperation error in job enqueueing test #15261

Closed
opened 2025-12-30 00:20:56 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18062
Author: @bctiemann
Created: 11/21/2024
Status: Merged
Merged: 11/21/2024
Merged by: @jeremystretch

Base: developHead: 17950-fix-enqueue-job-test


📝 Commits (5)

  • fb7c3eb Wait until job1 exists in Redis before enqueueing job2
  • aa9d4a1 Job can exist but not have status
  • c14542c Catch InvalidJobOperation and use as trigger for retry
  • 4595eaf Catch InvalidJobOperation when deleting/canceling job
  • d4fbce5 Remove testing code

📊 Changes

1 file changed (+6 additions, -1 deletions)

View changed files

📝 netbox/core/models/jobs.py (+6 -1)

📄 Description

Fixes: #17950

This alters the Job.delete() method to wrap job.cancel() in a try-except which handles the condition where the inner get_status call fails to find a non-null status for the job in Redis. This should fix a recurring intermittent test failure in test_enqueue_once_after_enqueue.

My investigation showed that whereas the job UUID key must be in Redis in order for fetch_job to work (which occurs in delete prior to the cancel call), it is occasionally the case that a call to self.connection.hget(self.key, 'status') returns a null value, leading to the exception being raised in rq/job.py#L400. This never occurs locally, and may be a side effect of concurrency within the CI environment.

The risk of this fix is low, I think, because the job.cancel is only being used in order to clear out a job from the cache during a delete operation; leaving a job in undeleted or partially-deleted state (particularly specifically in CI) is unlikely to have negative side effects.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/18062 **Author:** [@bctiemann](https://github.com/bctiemann) **Created:** 11/21/2024 **Status:** ✅ Merged **Merged:** 11/21/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `17950-fix-enqueue-job-test` --- ### 📝 Commits (5) - [`fb7c3eb`](https://github.com/netbox-community/netbox/commit/fb7c3ebd266046ca739446b7868e8e8f82646fc6) Wait until job1 exists in Redis before enqueueing job2 - [`aa9d4a1`](https://github.com/netbox-community/netbox/commit/aa9d4a1f1bcd5271bdb36ff949ad8da27c866713) Job can exist but not have status - [`c14542c`](https://github.com/netbox-community/netbox/commit/c14542c8cc2cce22e370b954367ade6bd58f7539) Catch InvalidJobOperation and use as trigger for retry - [`4595eaf`](https://github.com/netbox-community/netbox/commit/4595eafd3805e561aa905bde9cdc2fe0f9e573f5) Catch InvalidJobOperation when deleting/canceling job - [`d4fbce5`](https://github.com/netbox-community/netbox/commit/d4fbce571824a9d8aebac8192551f2c5e352f849) Remove testing code ### 📊 Changes **1 file changed** (+6 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `netbox/core/models/jobs.py` (+6 -1) </details> ### 📄 Description ### Fixes: #17950 This alters the `Job.delete()` method to wrap `job.cancel()` in a try-except which handles the condition where the inner `get_status` call fails to find a non-null status for the job in Redis. This should fix a recurring intermittent test failure in `test_enqueue_once_after_enqueue`. My investigation showed that whereas the job UUID key must be in Redis in order for `fetch_job` to work (which occurs in `delete` prior to the `cancel` call), it is occasionally the case that a call to `self.connection.hget(self.key, 'status')` returns a null value, leading to the exception being raised in `rq/job.py#L400`. This never occurs locally, and may be a side effect of concurrency within the CI environment. The risk of this fix is low, I think, because the `job.cancel` is only being used in order to clear out a job from the cache during a `delete` operation; leaving a job in undeleted or partially-deleted state (particularly specifically in CI) is unlikely to have negative side effects. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:20:56 +01:00
adam closed this issue 2025-12-30 00:20:56 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15261