mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 20:10:10 +03:00
Remove Django 1.6 transaction compat
This commit is contained in:
parent
c33d0069da
commit
4fecb8eca6
|
@ -250,7 +250,7 @@ else:
|
|||
|
||||
# pytz is required from Django 1.11. Remove when dropping Django 1.10 support.
|
||||
try:
|
||||
import pytz # noqa
|
||||
import pytz # noqa
|
||||
from pytz.exceptions import InvalidTimeError
|
||||
except ImportError:
|
||||
InvalidTimeError = Exception
|
||||
|
@ -298,20 +298,9 @@ class MaxLengthValidator(CustomValidatorMessage, validators.MaxLengthValidator):
|
|||
|
||||
|
||||
def set_rollback():
|
||||
if hasattr(transaction, 'set_rollback'):
|
||||
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
|
||||
# If running in >=1.6 then mark a rollback as required,
|
||||
# and allow it to be handled by Django.
|
||||
if connection.in_atomic_block:
|
||||
transaction.set_rollback(True)
|
||||
elif transaction.is_managed():
|
||||
# Otherwise handle it explicitly if in managed mode.
|
||||
if transaction.is_dirty():
|
||||
transaction.rollback()
|
||||
transaction.leave_transaction_management()
|
||||
else:
|
||||
# transaction not managed
|
||||
pass
|
||||
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
|
||||
if connection.in_atomic_block:
|
||||
transaction.set_rollback(True)
|
||||
|
||||
|
||||
def authenticate(request=None, **credentials):
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from rest_framework import compat
|
||||
|
||||
|
||||
class CompatTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.original_django_version = compat.django.VERSION
|
||||
self.original_transaction = compat.transaction
|
||||
|
||||
def tearDown(self):
|
||||
compat.django.VERSION = self.original_django_version
|
||||
compat.transaction = self.original_transaction
|
||||
|
||||
def test_set_rollback_for_transaction_in_managed_mode(self):
|
||||
class MockTransaction(object):
|
||||
called_rollback = False
|
||||
called_leave_transaction_management = False
|
||||
|
||||
def is_managed(self):
|
||||
return True
|
||||
|
||||
def is_dirty(self):
|
||||
return True
|
||||
|
||||
def rollback(self):
|
||||
self.called_rollback = True
|
||||
|
||||
def leave_transaction_management(self):
|
||||
self.called_leave_transaction_management = True
|
||||
|
||||
dirty_mock_transaction = MockTransaction()
|
||||
compat.transaction = dirty_mock_transaction
|
||||
compat.set_rollback()
|
||||
assert dirty_mock_transaction.called_rollback is True
|
||||
assert dirty_mock_transaction.called_leave_transaction_management is True
|
||||
|
||||
clean_mock_transaction = MockTransaction()
|
||||
clean_mock_transaction.is_dirty = lambda: False
|
||||
compat.transaction = clean_mock_transaction
|
||||
compat.set_rollback()
|
||||
assert clean_mock_transaction.called_rollback is False
|
||||
assert clean_mock_transaction.called_leave_transaction_management is True
|
Loading…
Reference in New Issue
Block a user