Skip to content
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

TypeError 'NoneType' object is not subscriptable #467

Open
mthompson313 opened this issue Aug 23, 2024 · 4 comments
Open

TypeError 'NoneType' object is not subscriptable #467

mthompson313 opened this issue Aug 23, 2024 · 4 comments

Comments

@mthompson313
Copy link

I am seeing an issue where asgiref/local.py is throwing a TypeError 'NoneType' object is not subscriptable

this is being thrown from:

def __getattr__(self, key):
        storage_object = self._data.get({})
        try:
            return storage_object[key]
        except KeyError:
            raise AttributeError(f"{self!r} object has no attribute {key!r}")
@andrewgodwin
Copy link
Member

Could I get a full traceback please plus the code that's calling it?

@mthompson313
Copy link
Author

Full Stack Trace:

TypeError: 'NoneType' object does not support item assignment
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "ddtrace/contrib/trace_utils.py", line 334, in wrapper
    return func(mod, pin, wrapped, instance, args, kwargs)
  File "ddtrace/contrib/django/patch.py", line 302, in wrapped
    return func(*args, **kwargs)
  File "axes/middleware.py", line 37, in __call__
    response = self.get_response(request)
  File "asgiref/local.py", line 124, in __setattr__
    setattr(storage, key, value)
  File "asgiref/local.py", line 28, in __setattr__
    storage_object[key] = value
TypeError: 'NoneType' object is not subscriptable
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "ddtrace/contrib/trace_utils.py", line 334, in wrapper
    return func(mod, pin, wrapped, instance, args, kwargs)
  File "ddtrace/contrib/django/patch.py", line 302, in wrapped
    return func(*args, **kwargs)
  File "discovery_service/middleware.py", line 119, in __call__
    response = self.get_response(request)
  File "django/core/handlers/exception.py", line 57, in inner
    response = response_for_exception(request, exc)
  File "django/core/handlers/exception.py", line 141, in response_for_exception
    request, get_resolver(get_urlconf()), sys.exc_info()
  File "django/urls/base.py", line 145, in get_urlconf
    return getattr(_urlconfs, "value", default)
  File "asgiref/local.py", line 118, in __getattr__
    return getattr(storage, key)
  File "asgiref/local.py", line 19, in __getattr__
    return storage_object[key]
TypeError: 'NoneType' object is not subscriptable
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "ddtrace/contrib/trace_utils.py", line 334, in wrapper
    return func(mod, pin, wrapped, instance, args, kwargs)
  File "ddtrace/contrib/django/patch.py", line 302, in wrapped
    return func(*args, **kwargs)
  File "discovery_service/middleware.py", line 16, in __call__
    response = self.get_response(request)
  File "django/core/handlers/exception.py", line 57, in inner
    response = response_for_exception(request, exc)
  File "django/core/handlers/exception.py", line 141, in response_for_exception
    request, get_resolver(get_urlconf()), sys.exc_info()
  File "django/urls/base.py", line 145, in get_urlconf
    return getattr(_urlconfs, "value", default)
  File "asgiref/local.py", line 118, in __getattr__
    return getattr(storage, key)
  File "asgiref/local.py", line 19, in __getattr__
    return storage_object[key]
TypeError: 'NoneType' object is not subscriptable
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "ddtrace/contrib/trace_utils.py", line 334, in wrapper
    return func(mod, pin, wrapped, instance, args, kwargs)
  File "ddtrace/contrib/django/patch.py", line 302, in wrapped
    return func(*args, **kwargs)
  File "django/utils/deprecation.py", line 134, in __call__
    response = response or self.get_response(request)
  File "django/core/handlers/exception.py", line 57, in inner
    response = response_for_exception(request, exc)
  File "django/core/handlers/exception.py", line 141, in response_for_exception
    request, get_resolver(get_urlconf()), sys.exc_info()
  File "django/urls/base.py", line 145, in get_urlconf
    return getattr(_urlconfs, "value", default)
  File "asgiref/local.py", line 118, in __getattr__
    return getattr(storage, key)
  File "asgiref/local.py", line 19, in __getattr__
    return storage_object[key]
TypeError: 'NoneType' object is not subscriptable
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "ddtrace/contrib/trace_utils.py", line 334, in wrapper
    return func(mod, pin, wrapped, instance, args, kwargs)
  File "ddtrace/contrib/django/patch.py", line 302, in wrapped
    return func(*args, **kwargs)
  File "django/utils/deprecation.py", line 134, in __call__
    response = response or self.get_response(request)
  File "django/core/handlers/exception.py", line 57, in inner
    response = response_for_exception(request, exc)
  File "django/core/handlers/exception.py", line 141, in response_for_exception
    request, get_resolver(get_urlconf()), sys.exc_info()
  File "django/urls/base.py", line 145, in get_urlconf
    return getattr(_urlconfs, "value", default)
  File "asgiref/local.py", line 118, in __getattr__
    return getattr(storage, key)
  File "asgiref/local.py", line 19, in __getattr__
    return storage_object[key]

@mthompson313
Copy link
Author

@andrewgodwin the code calling it I am having hard time finding as this came from a sentry alert on a production box. but the farthest down line given is:

 else:
        @wraps(get_response)
        def inner(request):
            try:
                response = get_response(request)
            except Exception as exc:
                response = response_for_exception(request, exc)
            return response
        return inner

from django/core/handlers/exception.py

@andrewgodwin
Copy link
Member

Yeah, we're not going to be able to confirm if this is a true bug or not unless it's possible to get a reproduceable test case that doesn't have ddtrace in there mucking things up.

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

No branches or pull requests

2 participants