Skip to content

Honor explicit priority overrides on decorated jobs - #2551

Merged
selwin merged 1 commit into
rq:masterfrom
jipeng6036-del:fix/decorator-at-front-override
Oct 26, 2026
Merged

selwin merged 1 commit into
rq:masterfrom
jipeng6036-del:fix/decorator-at-front-override

Conversation

@jipeng6036-del

@jipeng6036-del jipeng6036-del commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Decorated jobs configured with at_front=True ignore a per-call at_front=False: the job is prepended to the backlog anyway. Distinguish an omitted option from False, retaining the decorator default when omitted. Add Redis-backed regression coverage for both defaults and all three call forms, plus a short documentation note.

For example, with an empty queue and this importable task module:

# tasks.py
from redis import Redis
from rq import Queue
from rq.decorators import job

connection = Redis(db=2)
queue = Queue('priority-demo', connection=connection)

@job(queue, connection=connection, at_front=True)
def task():
    return 'done'
from tasks import queue, task

first = queue.enqueue(task)
second = task.enqueue(at_front=False)
assert queue.job_ids == [first.id, second.id]

The assertion fails on baseline b6907c9578ffa3acfc978f10d9bfc17ede200065 and passes with a44060e42b0641d55378d671548390be8e1cd693.

Validation on Linux with Docker --init, Python 3.12.14, Redis 7.4.10 and redis-py 6.4.0:

  • New regression: baseline fails for default=True, override=False; candidate decorator tests: 16 passed, 6 subtests passed.
  • RUN_SLOW_TESTS_TOO=1 RUN_SSL_TESTS=1 hatch run test:cov --durations=5: 792 passed, including real TLS/slow tests.
  • Real rq worker --burst --url redis://127.0.0.1:6379/2 priority-proof-candidate: four jobs execute in urgent, default, backlog, append order; baseline instead executes append before backlog. All persisted statuses and return values were checked. Repeated successfully using the built, installed wheel.
  • hatch run test:typing, hatch run test:ruff check rq tests, formatting and pre-commit on the three changed files, sdist/wheel build and wheel installation: passed.

The optional full pre-commit run reformats two existing expressions in unchanged tests/test_worker_pool.py on both baseline and candidate; that unrelated formatting is left out. Hosted CI on a44060e now passes all 31 checks, including 14 Redis/Python combinations, 9 Valkey combinations and SSL (Test, Valkey).

AI assistance: Codex was used for investigation, implementation, and local validation.

Summary by CodeRabbit

  • Bug Fixes
    • Decorated jobs now honor an explicit at_front=False override when enqueued, even if the decorator’s default is True. When no override is provided, the decorator’s configured setting applies.
  • Documentation
    • Clarified that the decorator’s at_front setting is the default and can be overridden for individual jobs using delay() or enqueue().

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dbe2ebc2-f30a-4d4a-be3e-8637b26969f4
Commits

Reviewing files that changed from the base of the PR and between b6907c9 and a44060e.

Files selected for processing: 3
  • docs/docs/index.md
  • rq/decorators.py
  • tests/test_decorator.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Decorated jobs now use the decorator’s at_front setting when no per-call value is provided. An explicit True or False passed to delay() or enqueue() overrides that setting. Tests and documentation cover this behavior.

Changes: Decorated job queue positioning

Layer / File(s) Summary
Apply per-call queue positioning overrides
rq/decorators.py, tests/test_decorator.py, docs/docs/index.md
The decorator uses its configured at_front value only when the per-call value is None. Tests check queue ordering for omitted and explicit values. Documentation describes the override.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: selwin, jlucas91, karech

Merge Risk: Minimal · up to a4406

The change correctly honors explicit queue-position overrides without establishing a merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: honoring explicit per-call priority overrides on decorated jobs.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.19%. Comparing base (2de9491) to head (a44060e).
⚠️ Report is 364 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2551      +/-   ##
==========================================
+ Coverage   93.61%   95.19%   +1.57%     
==========================================
  Files          28       43      +15     
  Lines        3760     5615    +1855     
==========================================
+ Hits         3520     5345    +1825     
- Misses        240      270      +30     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@selwin
selwin merged commit 65ac6d0 into rq:master Oct 26, 2026
31 checks passed
@selwin

selwin commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants