Django

Code

Ticket #7145 (closed: duplicate)

Opened 4 months ago

Last modified 4 months ago

'NoneType' object has no attribute 'year' in admin change list when using date_hierarchy with a date field with null values

Reported by: Eric Walstad <eric@ericwalstad.com> Assigned to: nobody
Milestone: Component: Admin interface
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In changeset r7511

AttributeError
'NoneType' object has no attribute 'year'
Exception Type:  	AttributeError
Exception Value: 	'NoneType' object has no attribute 'year'
Exception Location: 	/usr/lib/python2.5/site-packages/django/contrib/admin/templatetags/admin_list.py in date_hierarchy, line 271

In the following, years is getting set to [None]. That seems to happen when there are null values in the date field, as best I can tell:

            years = cl.query_set.dates(field_name, 'year')
            return {
                'show': True,
                'choices': [{
                    'link': link({year_field: year.year}),
                    'title': year.year
                } for year in years]
            }

Local vars:

_[3] 	[]
cl 	<django.contrib.admin.views.main.ChangeList object at 0x89c628c>
day_field 	'date_paid__day'
day_lookup 	None
field_generic 	'date_paid__'
field_name 	'date_paid'
link 	<function <lambda> at 0x8b5af44>
month_day_format 	u'F j'
month_field 	'date_paid__month'
month_lookup 	None
year 	None
year_field 	'date_paid__year'
year_lookup 	None
year_month_format 	u'F Y'
years 	[None]

My temporary work around is to not use date_hierarchy in the admin ui.

Attachments

Change History

05/02/08 08:42:45 changed by Evren Esat Özkan <sleytr@gmail.com>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Confirmed, same here with r7512. Error disappearing after deleting the records which has null dates.

05/02/08 08:56:22 changed by oyvind

  • status changed from new to closed.
  • resolution set to duplicate.

duplicate of #7147


Add/Change #7145 ('NoneType' object has no attribute 'year' in admin change list when using date_hierarchy with a date field with null values)




Change Properties
Action