Move set_rollback from compat => views

This commit is contained in:
Ryan P Kilby 2017-11-13 13:14:17 -05:00
parent 4fecb8eca6
commit 61db5f9de7
2 changed files with 8 additions and 9 deletions

View File

@ -12,7 +12,7 @@ from django.apps import apps
from django.conf import settings
from django.core import validators
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, models, transaction
from django.db import models
from django.utils import six
from django.views.generic import View
@ -297,12 +297,6 @@ class MaxLengthValidator(CustomValidatorMessage, validators.MaxLengthValidator):
pass
def set_rollback():
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
if connection.in_atomic_block:
transaction.set_rollback(True)
def authenticate(request=None, **credentials):
from django.contrib.auth import authenticate
if django.VERSION < (1, 11):

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.db import models
from django.db import connection, models, transaction
from django.http import Http404
from django.http.response import HttpResponseBase
from django.utils import six
@ -16,7 +16,6 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View
from rest_framework import exceptions, status
from rest_framework.compat import set_rollback
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.schemas import AutoSchema
@ -55,6 +54,12 @@ def get_view_description(view_cls, html=False):
return description
def set_rollback():
atomic_requests = connection.settings_dict.get('ATOMIC_REQUESTS', False)
if atomic_requests and connection.in_atomic_block:
transaction.set_rollback(True)
def exception_handler(exc, context):
"""
Returns the response that should be used for any given exception.