2

I have some django code that runs fine on a SQLite database or on a MySQL database, but it runs into problems with Postgres, and it's making me crazy that no one has has this issue before. I think it may also be related to the way querysets are evaluated by the pager.

In a view I have:

def index(request, page=1):
    latest_posts = Post.objects.all().order_by('-pub_date')
    paginator = Paginator(latest_posts, 5)
    try:
        posts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        posts = paginator.page(paginator.num_pages)
    return render_to_response('blog/index.html', {'posts' : posts})

And inside the template:

{% for post in posts.object_list %}
    {# some rendering jazz #}
{% endfor %}

This works fine with SQLite, but Postgres gives me:

Caught TypeError while rendering: 'NoneType' object is not callable

To further complicate things, when I switch the Queryset call to:

latest_posts = Post.objects.all()

Everything works great. I've tried re-reading the documentation, but found nothing, although I admit I'm a bit clouded by frustration at this point. What am I missing?

Thanks in advance.

pivotal
  • 736
  • 6
  • 16
  • AFAIK, the Paginator just adds LIMIT and OFFSET to the query from the QuerySet object. I never had problems with the Paginator and PostgreSQL so far. Try looping through the paginator and its object_lists in the shell with your QuerySet, maybe you'll get a more precise error message or you'll see that it runs fine. – Haes Feb 02 '11 at 08:09
  • Are you using `defaultdict` somewhere? – Tomasz Zieliński Feb 02 '11 at 10:04
  • I've tried running through everything in the shell, and it works fine, which makes the difficulty with the template even more frustrating. Somehow the template isn't able to get the object list from the page object. Going to play with it more I guess. I'm not sure what `defaultdict`, so I don't think I'm using it anywhere. – pivotal Feb 02 '11 at 15:12

1 Answers1

0

This was a terrible mistake on my part, no blame goes to Postgresql - the issue was popping up with the way one of my custom template tags was handling certain posts in the postgresql database that weren't present in the SQLite one. I'm still figuring out the issue, but this question is invalid.

pivotal
  • 736
  • 6
  • 16