Fixes: #17950 - Handle InvalidJobOperation error in job enqueueing test #18062
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #17950
This alters the
Job.delete()method to wrapjob.cancel()in a try-except which handles the condition where the innerget_statuscall fails to find a non-null status for the job in Redis. This should fix a recurring intermittent test failure intest_enqueue_once_after_enqueue.My investigation showed that whereas the job UUID key must be in Redis in order for
fetch_jobto work (which occurs indeleteprior to thecancelcall), it is occasionally the case that a call toself.connection.hget(self.key, 'status')returns a null value, leading to the exception being raised inrq/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.cancelis only being used in order to clear out a job from the cache during adeleteoperation; leaving a job in undeleted or partially-deleted state (particularly specifically in CI) is unlikely to have negative side effects.