Repository navigation
fix(redis): warn when the backend is configured with a non-UTF-8 encoding - #157
Merged
Merged
Conversation
This was referenced Sep 26, 2026
…ding Entries are always written as UTF-8 JSON, but the client decodes replies with the configured encoding, so under encoding="latin-1" a stored b"\xe9" read back as b"\xc3\xa9" without any error. AsyncRedisCacheBackend, and so load_from_config(), now emit a RuntimeWarning for any encoding other than UTF-8 (aliases such as "UTF8" are accepted). An unknown codec is still rejected by redis-py itself. #126 removes the parameter in 0.4.0. Closes #122
allen0099
force-pushed
the
fix/redis-non-utf8-encoding-warning
branch
from
September 26, 2026 11:31
acd3f21 to
0133733
Compare
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 #122.
Problem
The shared codec always writes UTF-8 JSON, but the Redis client decodes every reply with the configured
encoding. With anything else, non-ASCII content comes back corrupted and nothing reports it. Reproduced on a live Redis:Change
AsyncRedisCacheBackend.__init__emits aRuntimeWarningwhenencodingis not UTF-8. The name is normalised withcodecs.lookup, so"UTF8"and"utf_8"are accepted silently.load_from_config()goes through the same check. The warning points at the caller's line.LookupErrorwhen the client is built.encodingoption and read raw bytes #126 drops the parameter in 0.4.0.encodingdocstring,docs/BACKENDS.mdand the changelog explain why the encoding has to stay UTF-8.Tests
latin-1,utf-16andasciiwarn, attributed to the test file.load_from_configwarns. An unknown codec raisesLookupErrorwithout the warning.With the warning call removed, the five warning tests fail. The full suite passes against live Redis and Memcached (
CACHEX_REQUIRE_LIVE_SERVERS=1): 799 passed, 100% coverage.mypy --strictis clean.This and #156 each add a
### Fixedsection to## [Unreleased]. Whichever merges second needs a small CHANGELOG rebase.