Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect attribute reuse in redis.connection.CacheProxyConnection #3456

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,11 @@ def read_response(
and self._cache.get(self._current_command_cache_key).status
!= CacheEntryStatus.IN_PROGRESS
):
return copy.deepcopy(
res = copy.deepcopy(
self._cache.get(self._current_command_cache_key).cache_value
)
self._current_command_cache_key = None
return res

response = self._conn.read_response(
disable_decoding=disable_decoding,
Expand All @@ -932,6 +934,8 @@ def read_response(
cache_entry.cache_value = response
self._cache.set(cache_entry)

self._current_command_cache_key = None

return response

def pack_command(self, *args):
Expand Down
5 changes: 1 addition & 4 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):
)
proxy_connection.send_command(*["GET", "foo"], **{"keys": ["foo"]})
assert proxy_connection.read_response() == b"bar"
assert proxy_connection._current_command_cache_key is None
assert proxy_connection.read_response() == b"bar"

mock_connection.read_response.assert_called_once()
mock_cache.set.assert_has_calls(
[
call(
Expand All @@ -530,9 +530,6 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
call(CacheKey(command="GET", redis_keys=("foo",))),
]
)

Expand Down
Loading