Opened 81 minutes ago

Last modified 58 minutes ago

#36888 assigned Bug

acreate method doesn't call asave

Reported by: Mateusz Szymanowski Owned by: @…
Component: Database layer (models, ORM) Version: 6.0
Severity: Normal Keywords: acreate asave
Cc: Mateusz Szymanowski Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

acreate doesn't call asave method.

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()

    async def asave(self, *args, **kwargs):
        self.field += 1
        await super().asave(*args, **kwargs)

obj = await SimpleModel.objects.acreate(field=4)
obj.field # returns 4, should be 5

When you run create, it calls save().

Change History (1)

comment:1 by Mateusz Szymanowski, 58 minutes ago

Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top