Opened 8 years ago

Closed 8 years ago

#27894 closed Bug (invalid)

ATOMIC_REQUESTS setting isn't honored in second view called via as_view()

Reported by: Patrick Gerken Owned by: nobody
Component: Uncategorized Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My database has ATOMIC_REQUESTS set to true.

My view "a" calls a view "b" that adds items to the database.
Then my view "a" raises an exception.
The items created in the view "b" are in the database.

I tried to write a proper test in django to reproduce the failure but I think it is not working properly:
https://github.com/do3cc/django/commit/c9d7be5fde722b552dd4cb6276b1a1edf201f53f
I use a settings file that activates postgres and the test gets executed but I suspect that I must use the client to access the views.

This is roughly the code in question:

https://github.com/do3cc/django/blob/c9d7be5fde722b552dd4cb6276b1a1edf201f53f/tests/transactions/tests.py#L31-L36

I'd love to write a better testcase for it but I am a bit lost at the moment where to write that test case.

Change History (1)

comment:1 by Aymeric Augustin, 8 years ago

Resolution: invalid
Status: newclosed

That's an interesting question, but I'm not convinced ATOMIC_REQUESTS should apply to that case.

As the word REQUESTS in ATOMIC_REQUESTS implies, the atomicity is tied to an incoming HTTP request, and there's no HTTP request going through Django's HTTP / WSGI stack when the second view is called.

A view is just a Python function. Django isn't going to interfere when you call that function. You should wrap the call to the second view in an atomic block yourself when you call it to achive the desired effect.

Note: See TracTickets for help on using tickets.
Back to Top