[Django] #36047: `BaseConnectionHandler.close_all()` doesn't work with async clients

7 views
Skip to first unread message

Django

unread,
Dec 31, 2024, 3:24:31 PM12/31/24
to django-...@googlegroups.com
#36047: `BaseConnectionHandler.close_all()` doesn't work with async clients
--------------------------+-----------------------------------------------
Reporter: amirreza | Type: Bug
Status: new | Component: Core (Cache system)
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------+-----------------------------------------------
hi
in django.core.cache there is this code:

{{{
caches = CacheHandler()


def close_caches(**kwargs):
# Some caches need to do a cleanup at the end of a request cycle. If
not
# implemented in a particular backend cache.close() is a no-op.
caches.close_all()
}}}

where `CacheHandler` is a subclass of `BaseConnectionHandler`
`close_all()` looks like this:

{{{
def close_all(self):
for conn in self.all(initialized_only=True):
conn.close()
}}}


but when a async client is at work, `.close()` doesn't work, it needs to
be `await conn.aclose()`

note that in my case (django-valkey) there is no way for async clients to
implement a sync method for `close`

p.s: i know django doesn't fully support async cache clients, i open this
issue so the problem doesn't get lost
--
Ticket URL: <https://code.djangoproject.com/ticket/36047>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 31, 2024, 3:25:09 PM12/31/24
to django-...@googlegroups.com
#36047: `BaseConnectionHandler.close_all()` doesn't work with async clients
-------------------------------------+-------------------------------------
Reporter: amirreza | Owner: (none)
Type: Bug | Status: new
Component: Core (Cache system) | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by amirreza:

Old description:

> hi
> in django.core.cache there is this code:
>
> {{{
> caches = CacheHandler()
>

> def close_caches(**kwargs):
> # Some caches need to do a cleanup at the end of a request cycle. If
> not
> # implemented in a particular backend cache.close() is a no-op.
> caches.close_all()
> }}}
>
> where `CacheHandler` is a subclass of `BaseConnectionHandler`
> `close_all()` looks like this:
>
> {{{
> def close_all(self):
> for conn in self.all(initialized_only=True):
> conn.close()
> }}}
>

> but when a async client is at work, `.close()` doesn't work, it needs to
> be `await conn.aclose()`
>
> note that in my case (django-valkey) there is no way for async clients to
> implement a sync method for `close`
>
> p.s: i know django doesn't fully support async cache clients, i open this
> issue so the problem doesn't get lost

New description:

hi
in django.core.cache there is this code:

{{{
caches = CacheHandler()


def close_caches(**kwargs):
# Some caches need to do a cleanup at the end of a request cycle. If
not
# implemented in a particular backend cache.close() is a no-op.
caches.close_all()
}}}

where `CacheHandler` is a subclass of `BaseConnectionHandler`
`close_all()` looks like this:

{{{
def close_all(self):
for conn in self.all(initialized_only=True):
conn.close()
}}}


but when an async client is at work, `.close()` doesn't work, it needs to
be `await conn.aclose()`

note that in my case (django-valkey) there is no way for async clients to
implement a sync method for `close`

p.s: i know django doesn't fully support async cache clients, i open this
issue so the problem doesn't get lost

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36047#comment:1>

Django

unread,
Jan 1, 2025, 9:44:28 PM1/1/25
to django-...@googlegroups.com
#36047: `BaseConnectionHandler.close_all()` doesn't work with async clients
-------------------------------------+-------------------------------------
Reporter: amirreza | Owner: (none)
Type: Bug | Status: new
Component: Core (Cache system) | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim Graham):

Is this ticket actionable before Django supports async cache clients?
--
Ticket URL: <https://code.djangoproject.com/ticket/36047#comment:2>

Django

unread,
Jan 2, 2025, 4:08:33 AM1/2/25
to django-...@googlegroups.com
#36047: `BaseConnectionHandler.close_all()` doesn't work with async clients
-------------------------------------+-------------------------------------
Reporter: amirreza | Owner: (none)
Type: Bug | Status: closed
Component: Core (Cache system) | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => invalid
* status: new => closed

Comment:

Agreed, as we don't have support for async clients, this isn't a valid
bug. I will link this to #33573 as I believe this was raised to be
informational
--
Ticket URL: <https://code.djangoproject.com/ticket/36047#comment:3>
Reply all
Reply to author
Forward
0 new messages