#7199 closed (duplicate)
Admin Page Not Listing Objects
Reported by: | 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
- result = node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/init.py" in render
- dict = func(*args)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/templatetags/admin_list.py" in date_hierarchy
- } for year in years]
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _result_iter
- self._fill_cache()
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _fill_cache
- self._result_cache.append(self._iter.next())
File "/usr/lib/python2.5/site-packages/django/db/models/sql/subqueries.py" in results_iter
- date = typecast_timestamp(str(date))
File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in typecast_timestamp
- if not ' ' in s: return typecast_date(s)
File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in typecast_date
- 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 , 17 years ago
comment:2 by , 16 years ago
Keywords: | qsrf-cleanup added |
---|---|
Triage Stage: | Unreviewed → Accepted |
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 , 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 , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
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 , 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.
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):