[Django] #34112: Add async-compatible interface to Model

4 views
Skip to first unread message

Django

unread,
Oct 21, 2022, 12:27:30 PM10/21/22
to django-...@googlegroups.com
#34112: Add async-compatible interface to Model
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: nobody
Johnson |
Type: New | Status: new
feature |
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Following #33646, it would be convenient to also have an async interface
on `Model` methods that use the database:

* `Model.asave()` to mirror `save()`
* `Model.adelete()` to mirror `delete()`
* `Model.arefresh_from_db()` to mirror `refresh_from_db()`

Allowing usage like:

{{{
book = await Book.objects.aget(title=title)
book.pages = ...
await book.asave()
}}}

There’s already a way to effectively call save for new objects only,
through the `QuerySet.acreate()` method, exposed on managers.

`Model` also has some database-touching methods used in form validation,
like `validate_constraints()`. But if we aren’t intending on exposing the
forms API as async, yet, then these could be deferred

--
Ticket URL: <https://code.djangoproject.com/ticket/34112>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages