Skip to content

tests: fix usage of transaction.non_atomic_requests #6043

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

Merged
merged 1 commit into from
Jun 21, 2018

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jun 21, 2018

This currently fails with Django 2.1 (beta), and it looks like the
decorator should be used just as is in general?!

NonAtomicDBTransactionAPIExceptionTests.test_api_exception_rollback_transaction_non_atomic_view:

../django/django/db/transaction.py:277: in _non_atomic_requests
    view._non_atomic_requests.add(using)
E   AttributeError: 'function' object has no attribute '_non_atomic_requests'

During handling of the above exception, another exception occurred:
tests/test_atomic_requests.py:149: in test_api_exception_rollback_transaction_non_atomic_view
    response = self.client.get('/')
../django/django/test/client.py:527: in get
    response = super().get(path, data=data, secure=secure, **extra)
../django/django/test/client.py:339: in get
    **extra,
../django/django/test/client.py:414: in generic
    return self.request(**r)
../django/django/test/client.py:477: in request
    response = self.handler(environ)
../django/django/test/client.py:140: in __call__
    response = self.get_response(request)
../django/django/core/handlers/base.py:81: in get_response
    response = self._middleware_chain(request)
../django/django/core/handlers/exception.py:37: in inner
    response = response_for_exception(request, exc)
../django/django/core/handlers/exception.py:87: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
../django/django/core/handlers/exception.py:35: in inner
    response = get_response(request)
../django/django/utils/deprecation.py:91: in __call__
    response = response or self.get_response(request)
../django/django/core/handlers/exception.py:37: in inner
    response = response_for_exception(request, exc)
../django/django/core/handlers/exception.py:87: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
../django/django/core/handlers/exception.py:35: in inner
    response = get_response(request)
../django/django/utils/deprecation.py:91: in __call__
    response = response or self.get_response(request)
../django/django/core/handlers/exception.py:37: in inner
    response = response_for_exception(request, exc)
../django/django/core/handlers/exception.py:87: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
../django/django/core/handlers/exception.py:35: in inner
    response = get_response(request)
../django/django/utils/deprecation.py:91: in __call__
    response = response or self.get_response(request)
../django/django/core/handlers/exception.py:37: in inner
    response = response_for_exception(request, exc)
../django/django/core/handlers/exception.py:87: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
../django/django/core/handlers/exception.py:35: in inner
    response = get_response(request)
../django/django/utils/deprecation.py:91: in __call__
    response = response or self.get_response(request)
../django/django/core/handlers/exception.py:37: in inner
    response = response_for_exception(request, exc)
../django/django/core/handlers/exception.py:87: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
../django/django/core/handlers/exception.py:35: in inner
    response = get_response(request)
../django/django/core/handlers/base.py:128: in _get_response
    response = self.process_exception_by_middleware(e, request)
../django/django/core/handlers/base.py:126: in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
../django/django/views/decorators/csrf.py:54: in wrapped_view
    return view_func(*args, **kwargs)
../django/django/views/generic/base.py:68: in view
    return self.dispatch(request, *args, **kwargs)
../django/django/utils/decorators.py:42: in _wrapper
    bound_method = dec(bound_method)
../django/django/db/transaction.py:285: in non_atomic_requests
    return _non_atomic_requests(using, DEFAULT_DB_ALIAS)
../django/django/db/transaction.py:279: in _non_atomic_requests
    view._non_atomic_requests = {using}
E   AttributeError: 'method' object has no attribute '_non_atomic_requests'

Initially added in c292b3d by @hellysmile.

This currently fails with Django 2.1 (beta), and it looks like the
decorator should be used just as is in general?!

    NonAtomicDBTransactionAPIExceptionTests.test_api_exception_rollback_transaction_non_atomic_view:

    ../django/django/db/transaction.py:277: in _non_atomic_requests
        view._non_atomic_requests.add(using)
    E   AttributeError: 'function' object has no attribute '_non_atomic_requests'

    During handling of the above exception, another exception occurred:
    tests/test_atomic_requests.py:149: in test_api_exception_rollback_transaction_non_atomic_view
        response = self.client.get('/')
    ../django/django/test/client.py:527: in get
        response = super().get(path, data=data, secure=secure, **extra)
    ../django/django/test/client.py:339: in get
        **extra,
    ../django/django/test/client.py:414: in generic
        return self.request(**r)
    ../django/django/test/client.py:477: in request
        response = self.handler(environ)
    ../django/django/test/client.py:140: in __call__
        response = self.get_response(request)
    ../django/django/core/handlers/base.py:81: in get_response
        response = self._middleware_chain(request)
    ../django/django/core/handlers/exception.py:37: in inner
        response = response_for_exception(request, exc)
    ../django/django/core/handlers/exception.py:87: in response_for_exception
        response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    ../django/django/core/handlers/exception.py:35: in inner
        response = get_response(request)
    ../django/django/utils/deprecation.py:91: in __call__
        response = response or self.get_response(request)
    ../django/django/core/handlers/exception.py:37: in inner
        response = response_for_exception(request, exc)
    ../django/django/core/handlers/exception.py:87: in response_for_exception
        response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    ../django/django/core/handlers/exception.py:35: in inner
        response = get_response(request)
    ../django/django/utils/deprecation.py:91: in __call__
        response = response or self.get_response(request)
    ../django/django/core/handlers/exception.py:37: in inner
        response = response_for_exception(request, exc)
    ../django/django/core/handlers/exception.py:87: in response_for_exception
        response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    ../django/django/core/handlers/exception.py:35: in inner
        response = get_response(request)
    ../django/django/utils/deprecation.py:91: in __call__
        response = response or self.get_response(request)
    ../django/django/core/handlers/exception.py:37: in inner
        response = response_for_exception(request, exc)
    ../django/django/core/handlers/exception.py:87: in response_for_exception
        response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    ../django/django/core/handlers/exception.py:35: in inner
        response = get_response(request)
    ../django/django/utils/deprecation.py:91: in __call__
        response = response or self.get_response(request)
    ../django/django/core/handlers/exception.py:37: in inner
        response = response_for_exception(request, exc)
    ../django/django/core/handlers/exception.py:87: in response_for_exception
        response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
    ../django/django/core/handlers/exception.py:35: in inner
        response = get_response(request)
    ../django/django/core/handlers/base.py:128: in _get_response
        response = self.process_exception_by_middleware(e, request)
    ../django/django/core/handlers/base.py:126: in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
    ../django/django/views/decorators/csrf.py:54: in wrapped_view
        return view_func(*args, **kwargs)
    ../django/django/views/generic/base.py:68: in view
        return self.dispatch(request, *args, **kwargs)
    ../django/django/utils/decorators.py:42: in _wrapper
        bound_method = dec(bound_method)
    ../django/django/db/transaction.py:285: in non_atomic_requests
        return _non_atomic_requests(using, DEFAULT_DB_ALIAS)
    ../django/django/db/transaction.py:279: in _non_atomic_requests
        view._non_atomic_requests = {using}
    E   AttributeError: 'method' object has no attribute '_non_atomic_requests'
@blueyed blueyed mentioned this pull request Jun 21, 2018
@blueyed
Copy link
Contributor Author

blueyed commented Jun 21, 2018

Coverage says its fine.

https://codecov.io/gh/encode/django-rest-framework/pull/6043

Would be nice to have Codecov status integration btw.
E.g. for #6038 it would warn about not being covered fully then (see https://codecov.io/gh/encode/django-rest-framework/pulls).

@rpkilby rpkilby merged commit a44cb67 into encode:master Jun 21, 2018
@blueyed blueyed deleted the fix-decorator branch June 21, 2018 19:36
@cjerdonek
Copy link

FYI, the Django issue that caused this report should be fixed in the next release:
django/django#10091

@blueyed
Copy link
Contributor Author

blueyed commented Jun 30, 2018

@cjerdonek
Thanks!

pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
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.

3 participants