Skip to content

Conversation

@joshpwrk
Copy link

@joshpwrk joshpwrk commented Jan 13, 2026

Problem:
When using WSGI servers with django_valkey you get the following error:
/usr/local/lib/python3.10/site-packages/django/http/response.py:335: RuntimeWarning: coroutine 'close_async_caches' was never awaited

Reason:
The current implementation connects an async connection closer to request_finished, which creates un-awaited coroutines in WSGI environments where no event loop exists. Although the implementation checks whether the Valkey object is_async, the function itself is defined as await def and thus throws an error.

Furthermore, even if users set CLOSE_CONNECTION = False, this does not prevent django from running the buggy close_async_caches function.

Solution:
Create separate sync and async handlers, and only connect the async version when async backends are detected.

@amirreza8002
Copy link
Member

amirreza8002 commented Jan 22, 2026

hello 👋
can you please provide your cache configuration, and tell me how you run your app

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.

2 participants