Работает ли select_for_update(), если AUTOCOMMIT установлен в False в Django Rest-Framework
Я пишу задачу celery, которая будет вызываться при вставке строки в таблицу. Эта задача выполняется в транзакции, и задача также блокирует определенные строки нескольких таблиц.
Теперь давайте предположим, что это задание выполняется, когда AUTOCOMMIT & ATOMIC_REQUESTS включено.
Вот как это выглядит -
@app.task
@transaction.atomic
def celery_task(a, b):
result = Orders.objects.filter(filed = "Value")
# here the result might have 10 of records but I just need few of them based on a very
# specific business logic.
# so I pick those which are required and should be locked.
rows_to_lock = [result[0], result[1]] # has only ids of the rows in this list
# Now to put on the records which are in - rows_to_lock
result = Orders.objects.select_for_update().filter(id__in=rows_to_lock)
...
...
Теперь, когда эта задача celery вызывается дважды с двумя разными аргументами и в одно и то же время, и если результирующие строки заказов точно такие же, то я заметил, что блокировки для обновления записей не работают.
Does the decorator
@transaction.atomicworks with the current database configurations that I have?Will I be able to solve the issue if I set the
AUTOCOMMITasFalse?Also will I be able to use the decorator
@transaction.atomicifAUTOCOMMITis set asFalse?Do I have to make any changes to the transactions if I set
AUTOCOMMITasFalse?Does
select_for_update()support the current database configurations I have?