Skip to content

Reject decode_responses=True in ArqRedis with a clear error - #528

Open
bijay-odyssey wants to merge 1 commit into
python-arq:mainfrom
bijay-odyssey:fix-decode-responses-guard
Open

Reject decode_responses=True in ArqRedis with a clear error#528
bijay-odyssey wants to merge 1 commit into
python-arq:mainfrom
bijay-odyssey:fix-decode-responses-guard

Conversation

@bijay-odyssey

Copy link
Copy Markdown

Closes #505.

Problem

arq stores and deserializes job data as raw bytes (via pickle/msgpack). create_pool() never exposed decode_responses, but nothing stopped a user from constructing ArqRedis directly with decode_responses=True, or handing it a pre-built connection pool with that set. When that happens, internal code that assumes bytes (e.g. .decode() calls on job/result keys in _get_job_result/_get_job_def, and the job (de)serializers) breaks with confusing downstream errors instead of a clear message pointing at the actual cause.

Fix

ArqRedis.__init__ now checks the resolved connection_pool.connection_kwargs right after super().__init__() and raises a RuntimeError immediately if decode_responses is truthy. Checking the resolved connection pool (rather than just the raw kwarg) means it catches the setting regardless of how it reaches ArqRedis — a direct kwarg, or a pre-built pool passed via pool_or_conn (which is also the path create_pool()'s Sentinel branch and manual pool construction go through).

Also updated the ArqRedis docstring to note the restriction.

Testing

Added tests/test_connections.py covering:

  • decode_responses=True is rejected with a clear error
  • decode_responses=False (explicit) still works
  • decode_responses unset (existing default behavior) still works

Also manually verified the pool_or_conn-based construction path (used by create_pool) is caught the same way. No existing behavior changes for anyone not passing decode_responses.

arq stores and deserializes job data as raw bytes (via pickle/msgpack).
create_pool() never exposed decode_responses, but constructing ArqRedis
directly with decode_responses=True (or passing a pre-built connection
pool with it set) silently corrupts job execution instead of failing
clearly, since internal code assumes bytes throughout (e.g. .decode()
calls on job/result keys, deserializers expecting bytes).

Raise a RuntimeError immediately in ArqRedis.__init__ instead, checked
via the resolved connection_pool.connection_kwargs so it catches the
setting regardless of how it was passed in (direct kwarg or pool_or_conn).

Fixes python-arq#505
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
- Coverage   96.27%   95.86%   -0.42%     
==========================================
  Files          11       11              
  Lines        1074     1087      +13     
  Branches      209      145      -64     
==========================================
+ Hits         1034     1042       +8     
- Misses         19       24       +5     
  Partials       21       21              
Files with missing lines Coverage Δ
arq/connections.py 87.57% <100.00%> (-2.49%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ee4b48...7571c89. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Issue with decode_responses parameter in arq.ArqRedis

2 participants