DEV Community

Discussion on: Managing concurrency in Django using select_for_update

Collapse
 
serhatteker profile image
Serhat Teker

I'd like to suggest to use ATOMIC_REQUESTS setting:

Instead of transaction.atomic decorator, you can set ATOMIC_REQUESTS = True in the configuration of each database you want in your settings. As an example:

# settings.py

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "db_name",
        "USER": "db_user",
        "PASSWORD": "db_password",
        "HOST": "db_host",
        "PORT": "db_port",
        "ATOMIC_REQUESTS": True,
    }
}
Enter fullscreen mode Exit fullscreen mode