[Django]-Celery : task executed so fast that cannot retrieve updated DB

3👍

One way is to explicitly commit changes before call the celery task.

Example using django.db.transaction.commit_manually

from django.db import transaction

@transaction.commit_manually  # <----
def view(request, ...):
    query = SampleModel(field_A="A", field_B="B")
    query.save()
    transaction.commit()  # <----

    GetLastID.apply_async(args=[])

Leave a comment