Tengo una vista con transacción atómica, donde se crea un objeto y luego se actualiza:
def buy(request): with transaction.atomic(): # get request.user for update user = User.objects.select_for_update().get(id=request.user.id) user.order_count += 1 # get other stuff for update items = Item.objects.select_for_update().filter(sold=False) items.update(user=user) # DO I NEED select_for_update SOMEWHERE HERE FOR NEXT UPDATE? new_sell = Sell.objects.create(user=user) # some_operations() new_sell.some_field = something new_sell.save() HttpResponse('Done')¿Es seguro actualizar objetos recién creados sin select_for_update() en transacciones atómicas?
¿O cómo implementan las personas normales select_for_update en tales casos?
Supongo que esto será 100% seguro, pero no parece un buen plan:
new_sell = Sell.objects.create(user=user) sell = Sell.objects.select_for_update().get(id=new_sell.id) # Now we can do everything with sell object