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

support multi db atomic_requests #7739

Merged

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.

@tomchristie
Copy link
Member

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

Clear motivation, small footprint, cleanly done code change.

@tomchristie tomchristie 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
@tomchristie tomchristie 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