Skip to content

Conversation

@Kami
Copy link
Contributor

@Kami Kami commented Feb 11, 2020

I installed recommended version of Django (aka one which is specified in requirements.txt), yet the /result/add/json/ API endpoint returns an error when enabling authentication for that API endpoint (setting ALLOW_ANONYMOUS_POST config value to False).

Here is the error / exception:

Traceback (most recent call last):
  File "/home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages/codespeed/auth.py", line 36, in _decorator
    elif hasattr(request, 'user') and request.user.is_authenticated():
TypeError: 'bool' object is not callable
"POST /result/add/json/ HTTP/1.1" 500 86983

Environment:

$ python --version
Python 3.7.6
$ pip show django
Name: Django
Version: 2.1.15
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: [email protected]
License: BSD
Location: /home/kami/.virtualenvs/codespeed-py3/lib/python3.7/site-packages
Requires: pytz
Required-by: codespeed

Looking at the Django changelog, this behavior (method to attribute / property) changed in Django 2 which is installed by CodeSpeed by default (as per requirements.txt).

I assume this issue was never caught because no one who had authentication enabled ran CodeSpeed under Django 2+(?).

This pull request updates the authentication helper so it works with both versions of Django - one where that variable is a method (old versions) and one where it's a property (newer versions).

TODO

  • Tests

Kami added 3 commits February 11, 2020 20:20
where "request.user.is_authentication" variable is a property and not a
method (aka newer Django versions.)
@Kami
Copy link
Contributor Author

Kami commented Feb 11, 2020

I've added some mock based test cases in bed3f63.

@Kami
Copy link
Contributor Author

Kami commented Feb 13, 2020

@tobami When you get a chance, please let me know if there is anything else I need to do.

Thanks!

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.

2 participants