When you use async Django methods and you want to add custom logic in
asave method, when you create your object with acreate, it doesn't call
your asave method.
{{{
class SimpleModel(models.Model):
field = models.IntegerField()
Hello Natalia, my bad; I thought this ticket was inactive. I lately
realized the owner's PR is still ongoing, and there was no activity here
in the track ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/36888#comment:9>
Django
unread,
Mar 14, 2026, 10:38:24 AMMar 14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
Attempts in the PRs to remove that `sync_to_async()` stalled on the fact
that `GenericForeignKeyDescriptor.__set__` accesses the database (see
`generic_relations.tests.GenericRelationsTests.test_aadd`).
Here `self.field += 1` is what we might call ''business logic''. But
presumably we also are going to have the sync API for our model, and so
would need to duplicate this logic in the sync `save` method. But then
we're introducing a double entry bookkeeping requirement, which is
guaranteed to mean folks forget to update one or the other, and introduce
bugs into their application.
As it stands now, the ORM's async methods proxy directly/immediately to
their sync counterparts, which means that the one correct place for the
business logic is in `save`. Diluting that guarantee strikes me as a
concern.
--
Ticket URL: <https://code.djangoproject.com/ticket/36888#comment:12>
Django
unread,
Jul 24, 2026, 4:14:49 PM (5 days ago) Jul 24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
In the cache framework, async methods delegate to other async methods if
available, but given that folks mix business logic into `save()`, that
makes less sense for models. Reimplementing `acreate()` without a plan for
doing the same in `get_or_create()` or `update_or_create()` doesn't seem
prudent.
Quoting Simon from that forum thread:
> I’m not convinced that a core function is warranted here. I think it
might be better to invest efforts in coming up with a generic solution to
the problem of derived / generated fields and their interactions with
update_fields.
Maybe if we had that derived state feature in hand, and people had a nice
path to moving their business logic out of `save()`, we could take a fresh
look. Until then I don't think we can really advance this.
--
Ticket URL: <https://code.djangoproject.com/ticket/36888#comment:14>