list index out of range?

Issue #32 resolved
Soo Ling Lim created an issue

Hi Patrick,

First of all, thanks for django-postman. It's a fabulous app and I was very happy to find it.

I just upgraded from v2.1.1 to v3.0.0.

When there are no messages in the inbox, I get the error "list index out of range".

Error during template rendering In template /Users/soolinglim/Dropbox/kazoova/kazoova_website/templates/postman/base_folder.html, error at line 20

20 {% if pm_messages %}

Traceback

/Library/Python/2.7/site-packages/postman/query.py in as_sql

        alias = self.query.tables[0]

Thank you.

Comments (9)

  1. Patrick Samson repo owner
    • changed status to open

    An empty inbox should not be the problem. manage.py test postman.ViewTest.test_inbox works correctly ("No messages." is generated in the response)

    I can't reproduce the problem. Please provide more details and traces, review your customizations (for example " {% if pm_messages %}" is in line 18 in the original base_folder.html, not line 20)

  2. Soo Ling Lim reporter

    Hi Patrick,

    The problem seems to have disappeared...

    I am using Python 2.7.1, Django 1.4.3, Postgresql.

    Yesterday when I tried to upgrade to postman 3.0.0 using pip, it automatically upgraded my Django to 1.5.1, which messed up something (it gave me some warning about not uninstalling Django before installing a new version). After not being able to fix the index out of range error, I revert back to Django 1.4.3 and postman 2.1.1, and everything is back to normal. When I got your email, I did a pip install postman 3.0.0 to reproduce the problem but the problem seems to have gone....

    Thank you.

    Soo Ling

  3. lehins

    Hi guys. So I was getting the same issue. I am also using Postgresql and Django 1.5.1. So in query.py on line 42 after changing:

            alias = self.query.tables[0]
    

    to:

            alias = self.query.get_initial_alias()
    

    it fixed the IndexError but I am getting a 'substring not found' error now on line 47. Unfortunately I have not messed with django's db query stuff, so I won't be much help at the moment, but here is hopefully some useful info: http://lehins.lehins.com/www/postman_error.html Also I think it is relevant that those problems appear only in folders that are empty. (ex. if trash is not empty everything works.)

  4. Patrick Samson repo owner

    lehins, please revert to the original code, but add just above line 42:

            print sql, params
            print vars(self.query)
    

    and report the traces

  5. lehins
    SELECT COUNT(*) FROM "postman_message" ()
    {'aggregate_select_mask': None, '_aggregate_select_cache': None, 'extra': {}, 'join_map': {(None, u'postman_message', None, None): (u'postman_message',)}, 'related_select_fields': [], 'extra_tables': (), 'select_for_update': False, 'select': [], 'tables': [u'postman_message'], 'used_aliases': set([]), 'order_by': [], 'distinct': False, 'dupe_avoidance': {}, 'group_by': None, 'distinct_fields': [], 'alias_map': {u'postman_message': JoinInfo(table_name=u'postman_message', rhs_alias=u'postman_message', join_type=None, lhs_alias=None, lhs_join_col=None, rhs_join_col=None, nullable=False)}, 'select_related': False, 'deferred_loading': (set([]), True), 'select_fields': [], '_extra_select_cache': None, 'max_depth': 5, '_pm_table': ([], []), 'standard_ordering': True, 'extra_order_by': (), 'table_map': {u'postman_message': [u'postman_message']}, 'aggregates': {None: <django.db.models.sql.aggregates.Count object at 0x7f52a8dc9290>}, 'extra_select_mask': None, 'select_for_update_nowait': False, 'low_mark': 0, 'alias_refcount': {u'postman_message': 1}, 'related_select_cols': [], 'default_cols': False, 'ordering_aliases': [], 'having': <django.db.models.sql.where.WhereNode object at 0x7f52a8dc9350>, 'included_inherited_models': {}, 'default_ordering': False, 'where_class': <class 'django.db.models.sql.where.WhereNode'>, 'model': <class 'postman.models.Message'>, 'where': <django.db.models.sql.where.WhereNode object at 0x7f52a8dc9210>, 'high_mark': None, 'filter_is_sticky': False}
     ()
    {'aggregate_select_mask': None, '_aggregate_select_cache': None, 'extra': {u'count': (u'PM.count', [])}, 'join_map': {}, 'related_select_fields': [], 'extra_tables': (), 'select_for_update': False, 'select': [], 'tables': [], 'used_aliases': set([]), 'order_by': [], 'distinct': False, 'dupe_avoidance': {}, 'group_by': None, 'distinct_fields': [], 'alias_map': {}, 'select_related': {u'recipient': {}, u'sender': {}}, 'deferred_loading': (set([]), True), 'select_fields': [], '_extra_select_cache': None, 'max_depth': 5, '_pm_table': ([], []), 'standard_ordering': True, 'extra_order_by': (), 'table_map': {}, 'aggregates': {}, '_loaded_field_names_cache': {}, 'extra_select_mask': None, 'select_for_update_nowait': False, 'low_mark': 0, 'alias_refcount': {}, 'related_select_cols': [], 'default_cols': True, 'ordering_aliases': [], 'having': <django.db.models.sql.where.WhereNode object at 0x7f52a8dc9350>, 'included_inherited_models': {}, 'default_ordering': True, 'where_class': <class 'django.db.models.sql.where.WhereNode'>, 'model': <class 'postman.models.Message'>, 'where': <django.db.models.sql.where.WhereNode object at 0x7f52a8dc9210>, 'high_mark': 0, 'filter_is_sticky': False}
    

    plus the same traceback as in the link in previous post

  6. Patrick Samson repo owner

    Thanks for this hint. The problem is confirmed, it can be reproduced. It has to do with the presence of django-pagination. Hard work can begin...

  7. Log in to comment