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

AttributeError: 'thread._local' object has no attribute 'temp_identifier' #12

Closed
stevejalim opened this issue Jun 11, 2014 · 4 comments
Closed

Comments

@stevejalim
Copy link

Hi there

With both 0.1.1 and git HEAD, i'm getting the error pasted below.

Django 1.6.5 on OSX Python 2.7.5

Doesn't make a difference whether I'm using runserver or django-devserver for my local server.

Cheers
Steve

AttributeError: 'thread._local' object has no attribute 'temp_identifier'
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/core/handlers/base.py", line 194, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception
    'request': request
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1175, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1268, in _log
    self.handle(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1278, in handle
    self.callHandlers(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1318, in callHandlers
    hdlr.handle(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 749, in handle
    self.emit(record)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/errordite/handlers.py", line 90, in emit
    payload = self.enrich_errordite_payload(payload, record)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django_errordite/handlers.py", line 43, in enrich_errordite_payload
    if rq.user.is_anonymous():
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/utils/functional.py", line 213, in inner
    self._setup()
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/utils/functional.py", line 298, in _setup
    self._wrapped = self._setupfunc()
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 18, in <lambda>
    request.user = SimpleLazyObject(lambda: get_user(request))
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 10, in get_user
    request._cached_user = auth.get_user(request)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 140, in get_user
    user_id = request.session[SESSION_KEY]
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 47, in __getitem__
    return self._session[key]
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 173, in _get_session
    self._session_cache = self.load()
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py", line 20, in load
    expire_date__gt=timezone.now()
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
    return self.get_queryset().get(*args, **kwargs)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/db/models/query.py", line 304, in get
    num = len(clone)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
    self._fetch_all()
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/db/models/query.py", line 857, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
    for row in compiler.results_iter():
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/src/django-silk/silk/sql.py", line 48, in execute_sql
    DataCollector().register_query(query_dict)
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/src/django-silk/silk/collector.py", line 72, in register_query
    ident = self.get_identifier()
  File "/Volumes/HDD/Users/steve/.virtualenvs/yj/src/django-silk/silk/collector.py", line 26, in get_identifier
    self.local.temp_identifier += 1
AttributeError: 'thread._local' object has no attribute 'temp_identifier'
@mtford90
Copy link
Collaborator

That's my setup also... odd.

The only way I can see this happening is if silk.middleware.SilkyMiddleware.process_request is not called, which is where a thread local is configured. Do you have another piece of middleware that isn't playing ball?

Mike

@jbranc
Copy link

jbranc commented Jun 12, 2014

where you place the middleware matters. I haven't played enough to know, but adding it to the end of MIDDLEWARE_CLASSES caused this issue, where as bumping it up ahead of my custom middleware worked. YMMV

@stevejalim
Copy link
Author

Ah, I added it to the end of MIDDLEWARE_CLASSES too, as implied in https://github.com/mtford90/silk#installation -- perhaps a tweak to that secton of the README is all that's needed, plus a note to avoid putting it right at the end

@mtford90
Copy link
Collaborator

Yep, you're both right. If the middleware before SilkyMiddleware return something from process_request then Silk never gets the chance to run its own process_request and setup its thread local. See https://docs.djangoproject.com/en/dev/topics/http/middleware/#process-request for the explanation on this.

I'll update the README accordingly and also add some better error handling for this... Cheers guys.

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

3 participants