Skip to content

Conversation

@nickderobertis
Copy link
Contributor

@nickderobertis nickderobertis commented Oct 25, 2025

What

Adds the NoScriptError check/raise in SafeRedis, analogous to the change in Redis that was made in #355.

Why

Our Redis restarted for the first time (and thus cleared saved scripts) since we upgraded to include the changes in #355, and we started getting the following error printed in logs and caches never getting unlocked, spinning forever waiting for the unlock.

04:11:43 cashews.backends.redis.client ERROR   redis: can not execute command: EVALSHA
Traceback (most recent call last):
  File "/Users/nick/repos/cashews/cashews/backends/redis/client.py", line 38, in execute_command
    return await super().execute_command(command, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/repos/hellopatient/backend/.venv/lib/python3.13/site-packages/opentelemetry/instrumentation/redis/__init__.py", line 291, in _async_traced_execute_command
    response = await func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/repos/hellopatient/backend/.venv/lib/python3.13/site-packages/redis/asyncio/client.py", line 677, in execute_command
    return await conn.retry.call_with_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/Users/nick/repos/hellopatient/backend/.venv/lib/python3.13/site-packages/redis/asyncio/retry.py", line 50, in call_with_retry
    return await do()
           ^^^^^^^^^^
  File "/Users/nick/repos/hellopatient/backend/.venv/lib/python3.13/site-packages/redis/asyncio/client.py", line 652, in _send_command_parse_response
    return await self.parse_response(conn, command_name, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/repos/hellopatient/backend/.venv/lib/python3.13/site-packages/redis/asyncio/client.py", line 698, in parse_response
    response = await connection.read_response()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/repos/hellopatient/backend/.venv/lib/python3.13/site-packages/redis/asyncio/connection.py", line 627, in read_response
    raise response from None
redis.exceptions.NoScriptError: No matching script. Please use EVAL.

It seems that the new flow after #355 is to let the script get created by the redis lib upon getting the NoScriptError as we no longer explicitly call script_load. But when using SafeRedis rather than Redis, the error was getting swallowed and it was just returning None from client.evalsha rather than throwing, so it never triggers the except block to create the script. After these changes it does.

@codecov-commenter
Copy link

codecov-commenter commented Oct 25, 2025

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

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.10%. Comparing base (9c1fe76) to head (b8644fd).

Files with missing lines Patch % Lines
cashews/backends/redis/client.py 50.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #387      +/-   ##
==========================================
- Coverage   94.12%   94.10%   -0.03%     
==========================================
  Files          54       54              
  Lines        3594     3596       +2     
  Branches      460      460              
==========================================
+ Hits         3383     3384       +1     
- Misses        134      135       +1     
  Partials       77       77              
Flag Coverage Δ
unittests 94.02% <50.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@nickderobertis
Copy link
Contributor Author

Hey @Krukov , we are already running on this branch in production so no rush from our end, but just want to flag as I imagine this bug could be impacting other users.

@FlorianLB
Copy link

👍 we are facing the same issue

@Krukov Krukov merged commit 3daff1a into Krukov:master Dec 6, 2025
6 checks passed
@Krukov
Copy link
Owner

Krukov commented Dec 6, 2025

Thanks ! Sorry for the weak support

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.

4 participants