Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Django: Is it necessary to call select_for_update for recently created object in atomic transaction?

I have a view with atomic transaction, where one object is created then updated:

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

Is it safe to update newly created objects without select_for_update() in atomic transactions?

Or how do normal people implement select_for_update in such cases?

I guess, this will be 100% safe, but does not look like a good 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
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda