Skip to content

Commit 15024f3

Browse files
Ryan P Kilbycarltongibson
authored andcommitted
Remove set_rollback() from compat (#5591)
* Remove Django 1.6 transaction compat * Move set_rollback from compat => views
1 parent 265375c commit 15024f3

File tree

3 files changed

+9
-65
lines changed

3 files changed

+9
-65
lines changed

rest_framework/compat.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.conf import settings
1313
from django.core import validators
1414
from django.core.exceptions import ImproperlyConfigured
15-
from django.db import connection, models, transaction
15+
from django.db import models
1616
from django.utils import six
1717
from django.views.generic import View
1818

@@ -250,7 +250,7 @@ def md_filter_add_syntax_highlight(md):
250250

251251
# pytz is required from Django 1.11. Remove when dropping Django 1.10 support.
252252
try:
253-
import pytz # noqa
253+
import pytz # noqa
254254
from pytz.exceptions import InvalidTimeError
255255
except ImportError:
256256
InvalidTimeError = Exception
@@ -297,23 +297,6 @@ class MaxLengthValidator(CustomValidatorMessage, validators.MaxLengthValidator):
297297
pass
298298

299299

300-
def set_rollback():
301-
if hasattr(transaction, 'set_rollback'):
302-
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
303-
# If running in >=1.6 then mark a rollback as required,
304-
# and allow it to be handled by Django.
305-
if connection.in_atomic_block:
306-
transaction.set_rollback(True)
307-
elif transaction.is_managed():
308-
# Otherwise handle it explicitly if in managed mode.
309-
if transaction.is_dirty():
310-
transaction.rollback()
311-
transaction.leave_transaction_management()
312-
else:
313-
# transaction not managed
314-
pass
315-
316-
317300
def authenticate(request=None, **credentials):
318301
from django.contrib.auth import authenticate
319302
if django.VERSION < (1, 11):

rest_framework/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django.conf import settings
77
from django.core.exceptions import PermissionDenied
8-
from django.db import models
8+
from django.db import connection, models, transaction
99
from django.http import Http404
1010
from django.http.response import HttpResponseBase
1111
from django.utils import six
@@ -16,7 +16,6 @@
1616
from django.views.generic import View
1717

1818
from rest_framework import exceptions, status
19-
from rest_framework.compat import set_rollback
2019
from rest_framework.request import Request
2120
from rest_framework.response import Response
2221
from rest_framework.schemas import AutoSchema
@@ -55,6 +54,12 @@ def get_view_description(view_cls, html=False):
5554
return description
5655

5756

57+
def set_rollback():
58+
atomic_requests = connection.settings_dict.get('ATOMIC_REQUESTS', False)
59+
if atomic_requests and connection.in_atomic_block:
60+
transaction.set_rollback(True)
61+
62+
5863
def exception_handler(exc, context):
5964
"""
6065
Returns the response that should be used for any given exception.

tests/test_compat.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)