Django

Code

Ticket #7199 (new)

Opened 1 week ago

Last modified 1 week ago

Admin Page Not Listing Objects

Reported by: hickswright+django@gmail.com Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: Cc:
Triage Stage: Unreviewed Has patch: 0
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

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.

Attachments

Change History

05/08/08 13:44:56 changed by hickswright+django@gmail.com

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

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'


Add/Change #7199 (Admin Page Not Listing Objects)




Change Properties
Action