0

I have a problem that is driving me crazy. I've developed a django application using the built in server and am now trying to deploy it on a production server behind apache 2.2.

I have migrated the database from SQLite to PostgreSQL.

In the Django Admin, when I load of the 'change_list' view for the File object on the test server, it loads just fine. As soon as I do the same thing on the production server, I get the following:

AttributeError at /admin/wilder/file/

'unicode' object has no attribute 'year'

Request Method: GET
Request URL: https://<snip>.berkeley.edu/<snip>/admin/wilder/file/
Django Version: 1.4.1
Exception Type: AttributeError
Exception Value: 

'unicode' object has no attribute 'year'

Exception Location: <snip>/virtualenv/wilder/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py in date_hierarchy, line 302
Python Executable: <snip>/virtualenv/wilder/bin/uwsgi
Python Version: 2.7.5
Python Path: 

['<snip>/virtualenv/wilder/lib/python2.7/:<snip>/virtualenv/wilder/lib/python2.7/site-packages/:<snip>/ecog_patient_db',
 '.',
 '',
 '<snip>/virtualenv/wilder/lib/python2.7/site-packages/readline-6.2.4.1-py2.7-linux-x86_64.egg',
 '<snip>/virtualenv/wilder/lib/python27.zip',
 '<snip>/virtualenv/wilder/lib/python2.7',
 '<snip>/virtualenv/wilder/lib/python2.7/plat-linux2',
 '<snip>/virtualenv/wilder/lib/python2.7/lib-tk',
 '<snip>/virtualenv/wilder/lib/python2.7/lib-old',
 '<snip>/virtualenv/wilder/lib/python2.7/lib-dynload',
 '/home/knight/king/local/lib/python2.7',
 '/home/knight/king/local/lib/python2.7/plat-linux2',
 '/home/knight/king/local/lib/python2.7/lib-tk',
 '<snip>/virtualenv/wilder/lib/python2.7/site-packages',
 '<snip>/virtualenv/wilder/lib/python2.7/site-packages/PIL']

Server time: Wed, 25 Sep 2013 14:41:30 -0700



Error during template rendering

In template /<snip>/ecog_patient_db/templates/admin/change_list.html, error at line 90
'unicode' object has no attribute 'year'
80 {% endif %}
81 {% endblock %}
82 {% if cl.formset.errors %}
83 <p class="errornote">
84 {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
85 </p>
86 {{ cl.formset.non_form_errors }}
87 {% endif %}
88 <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
89 {% block search %}{% search_form cl %}{% endblock %}
90 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
91 
92 {% block filters %}
93 {% if cl.has_filters %}
94 <div id="changelist-filter">
95 <h2>{% trans 'Filter' %}</h2>
96 {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
97 </div>
98 {% endif %}
99 {% endblock %}
100 


Environment:


Request Method: GET
Request URL: https://wilder.berkeley.edu/wilder/admin/wilder/file/

Django Version: 1.4.1
Python Version: 2.7.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',
 'south',
 'reversion',
 'massadmin',
 'django_extensions',
 'ecog_patient_db.wilder')
Installed Middleware:
('johnny.middleware.LocalStoreClearMiddleware',
 'johnny.middleware.QueryCacheMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.transaction.TransactionMiddleware')


Template error:
In template <snip>/ecog_patient_db/templates/admin/change_list.html, error at line 90
   'unicode' object has no attribute 'year'
   80 :       {% endif %}
   81 :     {% endblock %}
   82 :     {% if cl.formset.errors %}
   83 :         <p class="errornote">
   84 :         {% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
   85 :         </p>
   86 :         {{ cl.formset.non_form_errors }}
   87 :     {% endif %}
   88 :     <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
   89 :       {% block search %}{% search_form cl %}{% endblock %}
   90 :       {% block date_hierarchy %} {% date_hierarchy cl %} {% endblock %}
   91 : 
   92 :       {% block filters %}
   93 :         {% if cl.has_filters %}
   94 :           <div id="changelist-filter">
   95 :             <h2>{% trans 'Filter' %}</h2>
   96 :             {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
   97 :           </div>
   98 :         {% endif %}
   99 :       {% endblock %}
   100 : 


Traceback:
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  136.                     response = response.render()
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/response.py" in render
  104.             self._set_content(self.rendered_content)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  81.         content = template.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/template/base.py" in render
  1178.                     _dict = func(*resolved_args, **resolved_kwargs)
File "<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in date_hierarchy
  302.                 if date_range['first'].year == date_range['last'].year:

Exception Type: AttributeError at /admin/wilder/file/
Exception Value: 'unicode' object has no attribute 'year'

The context around the error and ENVIRONMENT shows that the data_range variable is coming back as a string, yet the code expects it to be a datetime object:

<snip>/virtualenv/wilder/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py in date_hierarchy
            link = lambda d: cl.get_query_string(d, [field_generic])
            if not (year_lookup or month_lookup or day_lookup):
                # select appropriate start level
                date_range = cl.query_set.aggregate(first=models.Min(field_name),
                                                    last=models.Max(field_name))

                if date_range['first'] and date_range['last']:
                    if date_range['first'].year == date_range['last'].year:
                        ...
                        year_lookup = date_range['first'].year
                        if date_range['first'].month == date_range['last'].month:
                            month_lookup = date_range['first'].month

            if year_lookup and month_lookup and day_lookup:
                day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))

\u25bc Local vars
Variable Value
month_field 
'file_modification_date__month'

cl 
<django.contrib.admin.views.main.ChangeList object at 0x7f001c142f10>

year_field 
'file_modification_date__year'

field_generic 
'file_modification_date__'

date_range 
{'first': u'2005-01-27 11:05:14', 'last': u'2013-06-12 21:17:45.085712'}

day_field 
'file_modification_date__day'

month_lookup 
None

link 
<function <lambda> at 0x1250e60>

year_lookup 
None

day_lookup 
None

field_name 
'file_modification_date'

I can't for life of me figure out why suddenly this would fail on the production system. If I add ?file_modification_date__year=2006 then https://<snip>.berkeley.edu/<snip>/admin/wilder/file/?file_modification_date__year=2006 loads correctly. But https://<snip>.berkeley.edu/<snip>/admin/wilder/file/ is what triggers the error above, but only on the production server. Any clues? Is there any more information you guys need?

2
  • Could you indent your code properly, please? Sep 26, 2013 at 5:40
  • Is that better? I'm still getting use to the formatting here. Sep 26, 2013 at 17:33

1 Answer 1

0

Well, the was annoying. Flushing memcache did the trick. I was using johnny_cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.