[Django] #27894: ATOMIC_REQUESTS setting isn't honored in second view called via as_view()

5 views
Skip to first unread message

Django

unread,
Mar 2, 2017, 5:23:53 AM3/2/17
to django-...@googlegroups.com
#27894: ATOMIC_REQUESTS setting isn't honored in second view called via as_view()
------------------------------------------+------------------------
Reporter: Patrick Gerken | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27894>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 2, 2017, 7:39:12 AM3/2/17
to django-...@googlegroups.com
#27894: ATOMIC_REQUESTS setting isn't honored in second view called via as_view()
--------------------------------+--------------------------------------

Reporter: Patrick Gerken | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 1.10
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Aymeric Augustin):

* status: new => closed
* resolution: => invalid


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27894#comment:1>

Reply all
Reply to author
Forward
0 new messages