transactions

Atomic increment of a counter in django

Atomic increment of a counter in django Question: I’m trying to atomically increment a simple counter in Django. My code looks like this: from models import Counter from django.db import transaction @transaction.commit_on_success def increment_counter(name): counter = Counter.objects.get_or_create(name = name)[0] counter.count += 1 counter.save() If I understand Django correctly, this should wrap the function in a …

Total answers: 6

Threaded Django task doesn't automatically handle transactions or db connections?

Threaded Django task doesn't automatically handle transactions or db connections? Question: I’ve got Django set up to run some recurring tasks in their own threads, and I noticed that they were always leaving behind unfinished database connection processes (pgsql “Idle In Transaction”). I looked through the Postgres logs and found that the transactions weren’t being …

Total answers: 1

Django admin: Turning off DB transactions

Django admin: Turning off DB transactions Question: I noticed that by default, all updates in the django admin site are done as transactions. I need to either: – turn off transactions (globally or for a particular admin view) – inside of a save() method of an entity being saved via the admin interface, commit the …

Total answers: 4