Skip to content

Conversation

jmo-qap
Copy link
Contributor

@jmo-qap jmo-qap commented Mar 2, 2021

Description

When using https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-DATABASE-ATOMIC_REQUESTS, django wraps each invoked view with transactions to all databases (https://github.com/django/django/blob/master/django/core/handlers/base.py#L323-L330). #2887 resolved #2034 for the default database, only.

In particular, https://github.com/encode/django-rest-framework/blob/master/rest_framework/views.py#L67-103 does not handle the fact that multiple transactions can be created by django. This PR adds a unit test and associated fix to ensure DRF rollsback all transactions setup by django for ATOMIC_REQUESTS rather than just the default db's transaction.

Test Plan

Added unit tests. Fail with the old code, passes with the new code.

@lovelydinosaur
Copy link
Member

I'm very satisfied with this pull request yup, nicely done.

Clear motivation, small footprint, cleanly done code change.

@lovelydinosaur lovelydinosaur merged commit de7468d into encode:master Mar 3, 2021
stefanacin pushed a commit to stefanacin/django-rest-framework that referenced this pull request Mar 22, 2021
@lovelydinosaur lovelydinosaur mentioned this pull request Mar 25, 2021
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle ATOMIC_REQUESTS correctly.
2 participants