Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: A durable atomic block cannot be nested within another atomic block. #178

Closed
simevo opened this issue Dec 5, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@simevo
Copy link

simevo commented Dec 5, 2023

Describe the bug

with postgres DB and psycopg 3 driver, occurs randomly when creating entity or vendor etc.:

Request Method:	POST
Request URL:	http://localhost:8000/ledger/customer/simevo-pqr0mwbu/create/
Django Version:	4.2.8
Exception Type:	RuntimeError
Exception Value:	
A durable atomic block cannot be nested within another atomic block.
Exception Location:	/usr/local/lib/python3.11/site-packages/django/db/transaction.py, line 190, in __enter__
Raised during:	django_ledger.views.customer.CustomerModelCreateView
Python Executable:	/usr/local/bin/python3
Python Version:	3.11.6
Python Path:	
['/app',
 '/usr/local/lib/python311.zip',
 '/usr/local/lib/python3.11',
 '/usr/local/lib/python3.11/lib-dynload',
 '/usr/local/lib/python3.11/site-packages']
Server time:	Tue, 05 Dec 2023 13:23:52 +0000

To Reproduce

Expected behavior
it should create the entity

Screenshots
localhost_8000_ledger_customer_simevo-pqr0mwbu_create_

@elarroba elarroba self-assigned this Dec 5, 2023
@elarroba elarroba added the bug Something isn't working label Dec 5, 2023
@simevo
Copy link
Author

simevo commented Dec 6, 2023

I think I figured out what is going on here, nothing wrong with your code.

In here I set (as we normally do) ATOMIC_REQUESTS = true as per https://docs.djangoproject.com/en/4.2/topics/db/transactions/#tying-transactions-to-http-requests.

Turns out you already wrap all changes to the DB with transaction.atomic(durable=True): so the two approaches clash together.

I removed the setting:

--- a/django_ledger_starter/settings.py
+++ b/django_ledger_starter/settings.py
@@ -88,7 +88,6 @@ DATABASES = {
         "USER": env("DATABASE_USER"),
         "PASSWORD": env("DATABASE_PASSWORD"),
         "TEST": {"NAME": env("DATABASE_NAME")},
-        "ATOMIC_REQUESTS": True,
     }
 }
 if "DATABASE_HOST" in env:

and the problem goes away. I'll now update arrobalytics/django-ledger-starter#1

@simevo simevo closed this as completed Dec 6, 2023
simevo pushed a commit to simevo/django-ledger-starter that referenced this issue Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants