Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

List index out of range in pagemodel #760

Closed
gmcguire opened this Issue · 14 comments

7 participants

@gmcguire

During the course of normal edits (unfortunately I don't know which one caused this) the entire CMS began to return this stack:

Traceback (most recent call last):

 File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 100, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/usr/local/lib/python2.6/dist-packages/cms/views.py", line 101, in details
   return render_to_response(template_name, context)

 File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py", line 20, in render_to_response
   return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

 File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 186, in render_to_string
   return t.render(context_instance)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 173, in render
   return self._render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 167, in _render
   return self.nodelist.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 796, in render
   bits.append(self.render_node(node, context))

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 809, in render_node
   return node.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py", line 125, in render
   return compiled_parent._render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 167, in _render
   return self.nodelist.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 796, in render
   bits.append(self.render_node(node, context))

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 809, in render_node
   return node.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py", line 62, in render
   result = block.nodelist.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 796, in render
   bits.append(self.render_node(node, context))

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 809, in render_node
   return node.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py", line 62, in render
   result = block.nodelist.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 796, in render
   bits.append(self.render_node(node, context))

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 809, in render_node
   return node.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py", line 62, in render
   result = block.nodelist.render(context)

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 796, in render
   bits.append(self.render_node(node, context))

 File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py", line 809, in render_node
   return node.render(context)

 File "/usr/local/lib/python2.6/dist-packages/classytags/core.py", line 92, in render
   return self.render_tag(context, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/cms/templatetags/cms_tags.py", line 221, in render_tag
   content = get_placeholder_content(context, request, page, name, inherit)

 File "/usr/local/lib/python2.6/dist-packages/cms/templatetags/cms_tags.py", line 147, in get_placeholder_content
   content = render_placeholder(placeholder, context, name)

 File "/usr/local/lib/python2.6/dist-packages/cms/plugin_rendering.py", line 166, in render_placeholder
   c.extend(render_plugins(plugins, context, placeholder, processors))

 File "/usr/local/lib/python2.6/dist-packages/cms/plugin_rendering.py", line 118, in render_plugins
   c.append(plugin.render_plugin(context, placeholder, processors=processors))

 File "/usr/local/lib/python2.6/dist-packages/cms/models/pluginmodel.py", line 155, in render_plugin
   context = plugin.render(context, instance, placeholder_slot)

 File "/usr/local/lib/python2.6/dist-packages/cms/plugins/text/cms_plugins.py", line 53, in render
   'body': plugin_tags_to_user_html(instance.body, context, placeholder),

 File "/usr/local/lib/python2.6/dist-packages/cms/plugins/text/utils.py", line 51, in plugin_tags_to_user_html
   return OBJ_ADMIN_RE.sub(_render_tag, text)

 File "/usr/local/lib/python2.6/dist-packages/cms/plugins/text/utils.py", line 50, in _render_tag
   return obj.render_plugin(context, placeholder)

 File "/usr/local/lib/python2.6/dist-packages/cms/models/pluginmodel.py", line 155, in render_plugin
   context = plugin.render(context, instance, placeholder_slot)

 File "/usr/local/lib/python2.6/dist-packages/cms/plugins/link/cms_plugins.py", line 22, in render
   link = instance.page_link.get_absolute_url()

 File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 55, in _curried
   return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))

 File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 969, in get_absolute_url
   return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self, *args, **kwargs)

 File "/usr/local/lib/python2.6/dist-packages/cms/models/pagemodel.py", line 549, in get_absolute_url
   if self.parent_id and ancestors[-1].pk == home_pk and not self.get_title_obj_attribute("has_url_overwrite", language, fallback) and path:

IndexError: list index out of range

Regardless of what was done it seems that it should not be possible for a user to make this to occur.

@ojii
Collaborator

what version of:

  • Django
  • django-cms
  • Python
  • Database

are you using?

What are your CMS specific settings?

@gmcguire

Django 1.2.5
django-cms 2.1.3
Python 2.6.5
database is Postgres 9.0.3

CMS specific settings:

MIDDLEWARE_CLASSES = (
    'django.middleware.gzip.GZipMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    # Replaced by cms's MultilingualURLMiddleware below
    #'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'cms.middleware.multilingual.MultilingualURLMiddleware',
    'cms.middleware.media.PlaceholderMediaMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    # Disabled until we can conditionally enable it only for /content requests
    #'cms.middleware.toolbar.ToolbarMiddleware',
    'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.i18n",
    "django.core.context_processors.debug",
    "django.core.context_processors.request",
    "django.core.context_processors.media",
    'django.core.context_processors.csrf',
    "cms.context_processors.media",
)

CMS_SOFTROOT = True
CMS_MODERATOR = True
CMS_PERMISSION = True
CMS_REDIRECTS = True
CMS_SEO_FIELDS = True
CMS_FLAT_URLS = False
CMS_MENU_TITLE_OVERWRITE = True
CMS_HIDE_UNTRANSLATED = False
CMS_URL_OVERWRITE = True

INSTALLED_APPS includes classytags, cms, cms.plugins.[all of them], menus, mptt, publisher, reversion, and south.

@gmcguire

As an update after speaking with the staff involved - I believe this happened using Chrome when previewing a page for approval. After previewing the page appeared to be selected and - if true - easy to accidentally reorder in the page hierarchy. I suspect it was this reordering that caused the corruption of the pagemodel data. Two bugs here perhaps.

@gmcguire

I think this thread refers to the same issue:

http://groups.google.com/group/django-cms/browse_thread/thread/bdc8d229f2d6b665/0dea65df7e35aad1

Is there another bug open for this already?

@ojii ojii was assigned
@stephrdev

I tried to reproduce the bug according to the hint in the mailinglist thread without success. Can anybody reproduce the bug and provide a TestCase OR a guide to reproduce this with the current develop branch?
It seems that django-reversion could be the reason but we really need a prove to fix this annoying issue.

@ojii
Collaborator

Okay, whoever fixes this bug (once and for all), including tests, will get 100 USD via Paypal from me.

@ojii
Collaborator

And just to repeat what I said on the mailing list, the problem here is not the "Index out of range" but the fact that the MPTT tree breaks somewhere, causing pages to have a parent_id but no (mptt-) ancestors. A proper fix for this will prevent the tree from breaking.

@chrisglass
Collaborator

+50$ for the bounty (my personal money)

@ojii ojii referenced this issue from a commit in ojii/django-cms
@ojii ojii Okay this is a big one:
I wanted to fix #885, which I did.
However it appeared that Page.get_absolute_url was a complete mess.
So I ended up fixing that, by moving page-path (url) logic to post-save (Title/Page) signals and compute them there, and store them in Title.path.
This means Page.get_absolute_url() should be A LOT faster now (=faster menus?), however someone better check that first.
It also means that page/title writes (create,update,move,blah) will be SLOWER, but in my opinion, optimizing reads over writes is preferable.

As a little side effect this commit also potentially fixes #493  due to also fixing #770.

And a further side effect, it will HIDE but NOT FIX #760. Potentially making that bug even more obscure (however it might still show up in the signals).

As you can see, I've changed a lot of tests (because they looked broken in my opinion), so this patch should get extra care.
ba38d2e
@ojii ojii closed this issue from a commit
@ojii ojii Okay this is a big one:
I wanted to fix #885, which I did.
However it appeared that Page.get_absolute_url was a complete mess.
So I ended up fixing that, by moving page-path (url) logic to post-save (Title/Page) signals and compute them there, and store them in Title.path.
This means Page.get_absolute_url() should be A LOT faster now (=faster menus?), however someone better check that first.
It also means that page/title writes (create,update,move,blah) will be SLOWER, but in my opinion, optimizing reads over writes is preferable.

As a little side effect this commit also potentially fixes #493  due to also fixing #770.

And a further side effect, it will HIDE but NOT FIX #760. Potentially making that bug even more obscure (however it might still show up in the signals).

As you can see, I've changed a lot of tests (because they looked broken in my opinion), so this patch should get extra care.
ba38d2e
@ojii ojii closed this in ba38d2e
@ojii ojii reopened this
@ojii
Collaborator

NOT fixed by the commit linked there!

@puterleat

Is there an argument that plugins should behave like template variables and avoid raising errors at all? Perhaps this type of error should be caught and an error message displayed for staff users, but nothing displayed for other visitors?

I've had similar problems with plugins where some instance which is referred to gets deleted without a proper cascade occurring to clean up. In fact, the inherit plugin is particularly bad at this – I'll file a separate issue for that.

@ojii
Collaborator

While this is probably still an open issue, I feel myself forced to push this to 2.3.

@crooksey

Theres a bad weekend of weather here this weekend. Im going to look at this with django-cms 2.2 and django1.3 to see if I can replicate and try and help a bit more.

@vladyslav2

django = 1.3.1
djang-cms = 2.1.4 Final

make this error on sqlite3 and mysql when updating a page

update to djano-cms = 2.2 everything is all right

@ojii
Collaborator

I will close this for now, haven't heard of this in ages. Comment if this should be reopened.

@ojii ojii closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.