Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#7199 closed (duplicate)

Admin Page Not Listing Objects

Reported by: hickswright+django@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qsrf-cleanup
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Environment:

Request Method: GET
Request URL: *
Django Version: 0.97-pre-SVN-unknown
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.markup',
'django.contrib.humanize',
'django.contrib.redirects',
...]

Installed Middleware:
('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware')

Template error:
In template /usr/lib/python2.5/site-packages/django/contrib/admin/templates/admin/change_list.html, error at line 16

Caught an exception while rendering: invalid literal for int() with base 10: 'None'
6 : {% block coltype %}flex{% endblock %}

7 : {% block content %}

8 : <div id="content-main">

9 : {% block object-tools %}

10 : {% if has_add_permission %}

11 : <ul class="object-tools"><li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li></ul>

12 : {% endif %}

13 : {% endblock %}

14 : <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">

15 : {% block search %}{% search_form cl %}{% endblock %}

16 : {% block date_hierarchy %} {% date_hierarchy cl %} {% endblock %}

17 : {% block filters %}{% filters cl %}{% endblock %}

18 : {% block result_list %}{% result_list cl %}{% endblock %}

19 : {% block pagination %}{% pagination cl %}{% endblock %}

20 : </div>

21 : </div>

22 : {% endblock %}

23 :

Traceback:
File "/usr/lib/python2.5/site-packages/django/template/debug.py" in render_node

  1. result = node.render(context)

File "/usr/lib/python2.5/site-packages/django/template/init.py" in render

  1. dict = func(*args)

File "/usr/lib/python2.5/site-packages/django/contrib/admin/templatetags/admin_list.py" in date_hierarchy

  1. } for year in years]

File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _result_iter

  1. self._fill_cache()

File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _fill_cache

  1. self._result_cache.append(self._iter.next())

File "/usr/lib/python2.5/site-packages/django/db/models/sql/subqueries.py" in results_iter

  1. date = typecast_timestamp(str(date))

File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in typecast_timestamp

  1. if not ' ' in s: return typecast_date(s)

File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in typecast_date

  1. return s and datetime.date(*map(int, s.split('-'))) or None # returns None if s is null

Exception Type: ValueError at /admin/blog/entry/
Exception Value: invalid literal for int() with base 10: 'None'

Looking through the code, the problem appears to be in django/db/models/sql/subqueries.py on line 357:

date = typecast_timestamp(str(date))

If date is None, str(date) equals the string 'None', not the None object, which results in the tests for None in typecast_date() (django/db/backends/util.py:52) to not work properly. It seems that the test needs to be moved up into django/db/models/sql/subqueries.py.

Change History (5)

comment:1 by hickswright+django@…, 16 years ago

Sorry, probably wasn't specific enough on the repro.

This error is caused by accessing the admin interface, listing a bunch of blog posts. The model is pretty simple, this seems to be choking on a couple of posts that have a null datetime, specifically displaying the null datetime in the template.

Model:

class Entry(Model):

slug = SlugField(unique=True, max_length=256, prepopulate_from=('title',))
title = CharField(max_length=256)
dt = DateTimeField(null=True)
body = TextField()
published = BooleanField()

def get_absolute_url(self):

return '/blog/%s' % self.slug

def str(self):

return "%s - %s" % (str(self.dt), self.title,)

class Admin:

list_display = ('title', 'dt', 'published',)
search_fields = ('title', 'body')
date_hierarchy = 'dt'
fields = ((None, {'fields': ('title', 'dt', 'body', 'published', 'slug',)}),)

class Meta:

get_latest_by = 'dt'
ordering = ('-dt',)
verbose_name = 'entry'
verbose_name_plural = 'entries'

comment:2 by Karen Tracey <kmtracey@…>, 16 years ago

Keywords: qsrf-cleanup added
Triage Stage: UnreviewedAccepted

Same problem reported on the user's list here:

http://groups.google.com/group/django-users/browse_thread/thread/1b798dd6871743aa

Marking qsrf-cleanup since it seems this was introduced with queryset-refactor (poster says reverting to revision befroe qs-rf merge makes the problem go away).

comment:3 by StevenPotter, 16 years ago

The actual problem appears to be in the query that django is issuing to the database. Here is the query that is issued if I use a version of django from before the qs-rf merge.

SELECT CAST(DATE_FORMAT(test_app_gallery.publish_date, '%Y-01-01 00:00:00') AS DATETIME) FROM test_app_gallery WHERE test_app_gallery.publish_date IS NOT NULL GROUP BY 1 ORDER BY 1 ASC

You will notice the IS NOT NULL portion of that, so there is never a null result to trigger the above error.

Now here is the query that is issued post qs-rf merge

SELECT DISTINCT CAST(DATE_FORMAT(test_app_gallery.publish_date, '%Y-01-01 00:00:00') AS DATETIME) FROM test_app_gallery WHERE test_app_gallery.publish_date IS NULL ORDER BY 1 ASC

you will notice the IS NULL, so only null results are returned.

comment:4 by Karen Tracey <kmtracey@…>, 16 years ago

Resolution: duplicate
Status: newclosed

OK, given that information and a bit of scanning of the qsrf-cleanup tickets, I think this is a dup of #7155. There's a patch you can try in that ticket; if it does not fix the problem please reopen this one.

comment:5 by StevenPotter, 16 years ago

Yes, it is a duplicate, I just finished a patch that is identical to the one in 7155. It fixes the problem.

Note: See TracTickets for help on using tickets.
Back to Top