question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Django 2.0] TypeError: 'bool' object is not callable

See original GitHub issue

Hello, getting this error with Django 2.0, Python 3.6.3 and master branch of drf-extensions:

Traceback (most recent call last):
  File "/app/users/v1/tests/tests.py", line 278, in test_update
    response = self.client.get(url)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 291, in get
    response = super(APIClient, self).get(path, data=data, **extra)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 208, in get
    return self.generic('GET', path, **r)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 237, in generic
    method, path, data, content_type, secure, **extra)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 404, in generic
    return self.request(**r)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 288, in request
    return super(APIClient, self).request(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/test.py", line 240, in request
    request = super(APIRequestFactory, self).request(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/test/client.py", line 485, in request
    raise exc_value
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 90, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/cache/decorators.py", line 48, in inner
    kwargs=kwargs,
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/cache/decorators.py", line 63, in process_cache_response
    kwargs=kwargs
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/cache/decorators.py", line 94, in calculate_key
    kwargs=kwargs,
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/key_constructor/constructors.py", line 30, in __call__
    return self.get_key(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/key_constructor/constructors.py", line 50, in get_key
    kwargs=kwargs
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/key_constructor/constructors.py", line 74, in _get_key
    self.get_data_from_bits(**_kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/key_constructor/constructors.py", line 90, in get_data_from_bits
    result_dict[bit_name] = bit_instance.get_data(params=params, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework_extensions/key_constructor/bits.py", line 119, in get_data
    if hasattr(request, 'user') and request.user and request.user.is_authenticated():
TypeError: 'bool' object is not callable

As you can see, I am using your cache solution with UserKeyBit as one of the bits.

I haven’t found any change relevant on the Django 2.0 release notes, so that’s why I’m posting this as an issue instead of a PR with a solution. But I can volunteer to provide one if needed. Thanks for this amazing project!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

10reactions
David-OConnorcommented, Jan 3, 2018

Per that page: “Using User.is_authenticated() and User.is_anonymous() as methods rather than properties is no longer supported.”

4reactions
T-101commented, Jan 20, 2018

in dal/views.py, would this be satisfactory?

def has_add_permission(self, request):
    """Return True if the user has the permission to add a model."""
    try:
        user_is_authenticated = request.user.is_authenticated()
    except TypeError:
        user_is_authenticated = request.user.is_authenticated
    
    if not user_is_authenticated:
        return False

This approach would retain backwards compatibility

Read more comments on GitHub >

github_iconTop Results From Across the Web

is_authenticated() raises TypeError TypeError: 'bool' object ...
"object is not callable" error occurs when you are trying to behave an object like it is a method or function. in this...
Read more >
TypeError: 'bool' object is not callable in Python
The Python "TypeError: 'bool' object is not callable" occurs when we try to call a boolean value ( True or False ) as...
Read more >
A django bug on Queryset.delete
A django bug on Queryset.delete. 130 views ... My python version is 3.6.3 and Django is 2.0.3. ... TypeError: 'bool' object is not...
Read more >
[Code]-Python Error: 'numpy.bool_' object is not iterable-pandas
sum(True) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'bool' object is not iterable.
Read more >
bool' object is not callable django 2.0
1 . python使用json.jsonify 将结果转为json格式时,爆出如上TypeError: Object of type 'ndarray' is not JSON serializable错误。 @app.index, count = data_analyse ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found