aplpy/aplpy — Issue #49: Exception: 'thread._local' object has no attribute 'nesting'
Author: jbanyer
Created: 2012-01-12 02:34:19+00:00
State: open

Gday,

I'm getting an exception in aplpy 0.9.6: Exception Value: 'thread._local' object has no attribute 'nesting' (traceback below).

This is using aplpy as part of a Django website. The exception only occurs when serving the site using mod_wsgi in Apache. It does not occur using the Django development webserver (manage.py runserver).

I was able to eliminate the exception with the following patch, although I don't know aplpy well enough to know if it's a good change or not:

```
--- aplpy/aplpy/decorators.py	2011/07/25 04:31:39	115
+++ aplpy/aplpy/decorators.py	2011/07/25 04:36:41	116
@@ -11,6 +11,10 @@

def _auto_refresh(f, *args, **kwargs):
+ # Jay did this
+ if not mydata.__dict__.has_key("nesting"):
+ mydata.nesting = 0
+ # end Jay
if 'refresh' in kwargs:
refresh = kwargs.pop('refresh')
else:
```

Django traceback:

```
Environment:

Request Method: GET
Request URL: http://jayws.physics.usyd.edu.au:8050/vast/postage_stamps/40115.png

Django Version: 1.3
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'vast']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/jay/sites/vast/vast/vast/views.py" in postage_stamp
256. image_data = postage_stamp.get_postage_stamp(ds)
File "/home/jay/sites/vast/vast/vast/postage_stamp.py" in get_postage_stamp
194. return self.get_image(path, ds.image, sources=sources, size=[300,300], pan=[ds.ra, ds.dec, radius_deg])
File "/home/jay/sites/vast/vast/vast/postage_stamp.py" in get_image
162. self.save_image_aplpy(path, image, **kwargs)
File "/home/jay/sites/vast/vast/vast/postage_stamp.py" in save_image_aplpy
103. figure = aplpy.FITSFigure(fits_image.hdu, dpi=dpi, figsize=figsize, auto_refresh=False)
File "/home/jay/sites/vast/vast/aplpy/decorators.py" in _auto_refresh
18. mydata.nesting += 1

Exception Type: AttributeError at /postage_stamps/40115.png
Exception Value: 'thread._local' object has no attribute 'nesting'
```