Add shorthand aliases for json and pickle serializers#2401
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds string aliases for serializer configuration in RQ. Users can now pass ChangesSerializer Shorthand Aliases
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/docs/jobs.md`:
- Line 271: Remove the leading shell prompt from the command example: replace
the snippet "$ rq worker --serializer json" with a plain command line "rq worker
--serializer json" so it no longer triggers markdownlint MD014; update the code
block containing that exact string accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e88d7c1e-2b37-4f1a-a1d8-ce17bed2348e
📒 Files selected for processing (9)
docs/docs/jobs.mddocs/docs/workers.mdrq/cli/helpers.pyrq/cli/workers.pyrq/serializers.pytests/test_cli.pytests/test_queue.pytests/test_serializers.pytests/test_worker.py
|
|
||
| ```console | ||
| $ rq worker --serializer rq.serializers.JSONSerializer | ||
| $ rq worker --serializer json |
There was a problem hiding this comment.
Fix markdownlint MD014 in the console command example.
Line 271 includes a $ prompt, which triggers the configured lint rule for command snippets without output.
📎 Suggested doc-only fix
- $ rq worker --serializer json
+ rq worker --serializer json📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $ rq worker --serializer json | |
| rq worker --serializer json |
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 271-271: Dollar signs used before commands without showing output
(MD014, commands-show-output)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/docs/jobs.md` at line 271, Remove the leading shell prompt from the
command example: replace the snippet "$ rq worker --serializer json" with a
plain command line "rq worker --serializer json" so it no longer triggers
markdownlint MD014; update the code block containing that exact string
accordingly.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/docs/workers.md`:
- Around line 251-253: Remove the leading shell prompt character from the
example command in the Markdown fenced code block so it shows the raw command;
specifically update the console block that contains "rq worker --serializer
json" (currently prefixed with "$") to remove the "$" prefix and leave just the
command "rq worker --serializer json".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b5f56905-6944-49d2-a48a-57505816f91d
📒 Files selected for processing (7)
docs/docs/jobs.mddocs/docs/workers.mdrq/cli/helpers.pyrq/defaults.pyrq/serializers.pyrq/worker_pool.pytests/test_serializers.py
✅ Files skipped from review due to trivial changes (1)
- rq/cli/helpers.py
| ```console | ||
| $ rq worker --serializer rq.serializers.JSONSerializer | ||
| $ rq worker --serializer json | ||
| ``` |
There was a problem hiding this comment.
Remove the shell prompt in this command example (markdownlint MD014).
Line 252 includes a leading $ for a command without output; that triggers MD014.
📎 Suggested fix
```console
-$ rq worker --serializer json
+rq worker --serializer json</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
```suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 252-252: Dollar signs used before commands without showing output
(MD014, commands-show-output)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/docs/workers.md` around lines 251 - 253, Remove the leading shell prompt
character from the example command in the Markdown fenced code block so it shows
the raw command; specifically update the console block that contains "rq worker
--serializer json" (currently prefixed with "$") to remove the "$" prefix and
leave just the command "rq worker --serializer json".
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rq/queue.py (1)
920-983:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
Queue.parse_args()return shape change is a public API compatibility risk.On Line [963], switching to a bare tuple removes named-field access for callers of this public method. Any integration doing
parsed.job_id/parsed.timeoutwill break at runtime.Please keep a named return type (
QueueArgs/NamedTuple) or make this method private before changing its contract.Proposed compatibility-safe adjustment
- return ( + return QueueArgs( f, timeout, description, result_ttl, ttl, failure_ttl, depends_on, job_id, at_front, meta, retry, repeat, on_success, on_failure, on_stopped, pipeline, unique, args, kwargs, )# Outside this segment (module scope), reintroduce the named return type. # from typing import NamedTuple # # class QueueArgs(NamedTuple): # f: FunctionReferenceType # timeout: int | None # description: str | None # result_ttl: int | None # ttl: int | None # failure_ttl: int | None # depends_on: JobDependencyType | None # job_id: str | None # at_front: bool # meta: dict | None # retry: Retry | None # repeat: Repeat | None # on_success: Callback | Callable[..., Any] | None # on_failure: Callback | Callable[..., Any] | None # on_stopped: Callback | Callable[..., Any] | None # pipeline: Pipeline | None # unique: bool # args: tuple | list | None # kwargs: dict | None🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rq/queue.py` around lines 920 - 983, The change to Queue.parse_args removed the named return type, breaking public API consumers that expect attribute access (e.g., parsed.job_id); restore a named return by reintroducing a QueueArgs NamedTuple (or dataclass) at module scope with fields matching the returned values (f, timeout, description, result_ttl, ttl, failure_ttl, depends_on, job_id, at_front, meta, retry, repeat, on_success, on_failure, on_stopped, pipeline, unique, args, kwargs) and change Queue.parse_args to return QueueArgs(...) instead of a bare tuple; alternatively, if you intend to break the public contract, mark parse_args private, but prefer the QueueArgs approach to preserve compatibility.
🧹 Nitpick comments (1)
rq/worker_registration.py (1)
73-78: ⚡ Quick winPrefer explicit
Nonenarrowing over# type: ignoreinget_keys().On Line 77,
# type: ignoresuppresses a useful type-safety check. Switching to explicitis not Nonebranching keeps behavior the same and avoids masking futureNoneregressions.♻️ Proposed refactor
- if queue: + if queue is not None: redis = queue.connection redis_key = WORKERS_BY_QUEUE_KEY % queue.name else: - redis = connection # type: ignore + assert connection is not None + redis = connection redis_key = REDIS_WORKER_KEYS🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rq/worker_registration.py` around lines 73 - 78, Replace the "# type: ignore" by explicitly narrowing None for the fallback connection in get_keys(): instead of "redis = connection # type: ignore", branch on "if connection is not None" and assign redis = connection there, otherwise handle the missing connection case (raise a clear exception or return an empty result) so nullability is checked explicitly; keep the existing queue branch that sets redis_key = WORKERS_BY_QUEUE_KEY % queue.name and the fallback redis_key = REDIS_WORKER_KEYS, and reference the variables queue, connection, WORKERS_BY_QUEUE_KEY and REDIS_WORKER_KEYS to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rq/worker/base.py`:
- Around line 1192-1193: The code checks results[7] after building a pipeline
which is brittle; instead capture the pipeline index for the job heartbeat
before adding it and use that dynamic index to inspect the job heartbeat result
and decide whether to call self.connection.delete(job.key). Concretely: record
the pipeline length (e.g., prior_len = len(pipeline.commands) or the return
position) immediately before calling job.heartbeat()/pipeline.hset for the job,
then after executing the pipeline read results[prior_len] (or the stored index)
rather than results[7]; update the references around heartbeat(),
execution.heartbeat(), job.heartbeat(), results and the
self.connection.delete(job.key) call and add a short comment explaining the
indexing approach.
In `@rq/worker/worker_classes.py`:
- Around line 191-198: The spawned "-c" Python source currently embeds values
via raw string interpolation (self.key, job.id, queue.name) which can break on
quotes/newlines and risk injection; update the code that builds the "-c" string
to escape these values using a Python literal-safe representation (e.g. use
repr() or json.dumps on self.key, job.id, queue.name) before inserting them, and
replace the direct interpolations used with Worker.find_by_key, Job.fetch, and
Queue(...) so the child process receives safely quoted literals.
---
Outside diff comments:
In `@rq/queue.py`:
- Around line 920-983: The change to Queue.parse_args removed the named return
type, breaking public API consumers that expect attribute access (e.g.,
parsed.job_id); restore a named return by reintroducing a QueueArgs NamedTuple
(or dataclass) at module scope with fields matching the returned values (f,
timeout, description, result_ttl, ttl, failure_ttl, depends_on, job_id,
at_front, meta, retry, repeat, on_success, on_failure, on_stopped, pipeline,
unique, args, kwargs) and change Queue.parse_args to return QueueArgs(...)
instead of a bare tuple; alternatively, if you intend to break the public
contract, mark parse_args private, but prefer the QueueArgs approach to preserve
compatibility.
---
Nitpick comments:
In `@rq/worker_registration.py`:
- Around line 73-78: Replace the "# type: ignore" by explicitly narrowing None
for the fallback connection in get_keys(): instead of "redis = connection #
type: ignore", branch on "if connection is not None" and assign redis =
connection there, otherwise handle the missing connection case (raise a clear
exception or return an empty result) so nullability is checked explicitly; keep
the existing queue branch that sets redis_key = WORKERS_BY_QUEUE_KEY %
queue.name and the fallback redis_key = REDIS_WORKER_KEYS, and reference the
variables queue, connection, WORKERS_BY_QUEUE_KEY and REDIS_WORKER_KEYS to
locate the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c50dd2af-dbd8-4042-877c-306c3b83a8f6
📒 Files selected for processing (7)
rq/cron.pyrq/queue.pyrq/scripts.pyrq/serializers.pyrq/worker/base.pyrq/worker/worker_classes.pyrq/worker_registration.py
✅ Files skipped from review due to trivial changes (1)
- rq/scripts.py
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rq/serializers.py`:
- Around line 61-64: Replace the runtime assert with an explicit type check:
instead of "assert not isinstance(serializer, str)" perform an if
isinstance(serializer, str): raise TypeError(...) to validate the public
argument named serializer before the existing isinstance(serializer, Serializer)
check; keep the subsequent NotImplementedError for non-Serializer objects but
use the explicit check to ensure user-provided string serializers produce a
clear, stable error rather than an AssertionError that can be stripped by -O.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Summary by CodeRabbit
Release Notes
New Features
'json','pickle') for queues, workers, and CLI commands, simplifying setup from full class paths.Documentation
Tests