Reject decode_responses=True in ArqRedis with a clear error - #528
Open
bijay-odyssey wants to merge 1 commit into
Open
Reject decode_responses=True in ArqRedis with a clear error#528bijay-odyssey wants to merge 1 commit into
bijay-odyssey wants to merge 1 commit into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. @@ 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
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #505.
Problem
arq stores and deserializes job data as raw
bytes(via pickle/msgpack).create_pool()never exposeddecode_responses, but nothing stopped a user from constructingArqRedisdirectly withdecode_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 resolvedconnection_pool.connection_kwargsright aftersuper().__init__()and raises aRuntimeErrorimmediately ifdecode_responsesis truthy. Checking the resolved connection pool (rather than just the raw kwarg) means it catches the setting regardless of how it reachesArqRedis— a direct kwarg, or a pre-built pool passed viapool_or_conn(which is also the pathcreate_pool()'sSentinelbranch and manual pool construction go through).Also updated the
ArqRedisdocstring to note the restriction.Testing
Added
tests/test_connections.pycovering:decode_responses=Trueis rejected with a clear errordecode_responses=False(explicit) still worksdecode_responsesunset (existing default behavior) still worksAlso manually verified the
pool_or_conn-based construction path (used bycreate_pool) is caught the same way. No existing behavior changes for anyone not passingdecode_responses.