Intention behind `adelete` being a queryset method, and not available on a model instance?

73 views
Skip to first unread message

Jason Johns

unread,
Oct 21, 2022, 8:47:35 AM10/21/22
to Django developers (Contributions to Django itself)
I came across a reddit post yesterday about `adelete` raising an attribute error

r = await mymodel.objects.aget(some_name=myname) 
await r.adelete()

would throw an `AttributeError`,

whereas r = await mymodel.objects.filter(some_name=myname).adelete() works as expected.

I was a little curious about this, and adelete is explicitly called out in the queryset docs within the `delete` section.  but the models doc page only contains items about `delete`.  Is this intentional or not, and if it is intentional, perhaps a specific call-out in both queryset and model delete sections would help with clarification.

Adam Johnson

unread,
Oct 21, 2022, 9:57:33 AM10/21/22
to django-d...@googlegroups.com
This is intentional, as it stands. Django 4.1 only added async QuerySet methods, not async Model methods. Async model methods like adelete(), and perhaps asave(), would be the next logical step.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/82ba40ef-ea73-4492-a2c3-448dbd1b9245n%40googlegroups.com.

Jason Johns

unread,
Oct 21, 2022, 10:51:29 AM10/21/22
to Django developers (Contributions to Django itself)
gotcha, then perhaps a documentation tweak would be in order, on both queryset and model pages?  because as is, its unclear this is expected.

Adam Johnson

unread,
Oct 21, 2022, 11:50:08 AM10/21/22
to django-d...@googlegroups.com
If you have a suggestion, sure. But from my perspective the docs are clear. There's an adelete() method doc'd for QuerySet, and not for Model, and the release note says “QuerySet now provides an asynchronous interface...”.

Adam Johnson

unread,
Oct 21, 2022, 12:29:31 PM10/21/22
to django-d...@googlegroups.com
I opened a ticket to add async methods to Model: https://code.djangoproject.com/ticket/34112

This would be released in Django 4.2, at minimum.

Using async to perform model updates is not likely to be performant, since the queries end up being processed synchronously on a thread anyway. This is because the database libraries Django supports don't have async interfaces.

Jason Johns

unread,
Oct 22, 2022, 10:58:51 AM10/22/22
to Django developers (Contributions to Django itself)

The explanation makes sense, which is one thing that’s making me feel this is something to be called out in the documentation, because it is a difference in expectations in the api interface. Since a model has a delete method, as does a queryset, the absence of that equivalence for async is not what I would expect and it’s not obvious why. 
Reply all
Reply to author
Forward
0 new messages