Attention

This document was written for an unsupported version of Plone, Plone 2.1.x, and was last updated 1601 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

AttributeError: _length

by Lukas Zdych last modified Dec 30, 2008 03:08 PM
When you upgrade from Zope 2.7.x to 2.8.1 you get this error on most of the portal_catalog operations.

Note from the editor: This fix is included in the migration mechanism in the Plone 2.1.1 release and newer. So this should only happen if you are upgrading to the exact 2.1.0 release while upgrading your Zope from 2.7 to 2.8 at the same time.

I got this error message when moving Plone 2.1 from Zope 2.7.5 (Debian / Sarge) and 2.7.9 (FreeBSD) to Zope 2.8.1, but the same problems can be result of upgrading also Plone 2.0.5 to Plone 2.1 along with zope upgrade.

When you get this error after upgrade try the following steps to make successfull upgrade:

  1. install Zope 2.8.1 and Plone 2.1
  2. copy the Data.fs from your 2.7.x instance
  3. start new Zope
  4. go to the ZMI
  5. open portal_catalog inside your Plone instance
  6. you will get an "AttributeError, _length
  7. call the "manage_convertIndexes" method of the ZCatalog (by replacing the "manage_main" part of the URL with "manage_convertIndexes") - the URL should look something like this: http://localhost:8080/plonesite/portal_catalog/manage_convertIndexes
  8. depending on the size of your ZCatalog the migration may take a while
    • After the conversion a message will appear: "Indexes converted and reindexed".
  9. create new Python Script in portal_skins/custom folder with id (fix_catalog or whatever) and replace it's sample code with the following code:
    • return len(context.portal_catalog)
  10. save the script and click on Test tab in the top of page
    • You'll see a number appear, that's the number of items in your catalog. At the same time, your catalog length attrtibute will have been converted,
  11. go back to portal_catalog and click on Update Catalog button which can be found on Advanced tab
  12. open uid_catalog and click on Update Catalog button which is also on Advanced tab
  13. return back to fixing script fix_catalog and change the line of code to the following:
    • return len(context.reference_catalog)
  14. save the script and click on Test tab in the top of page
    • You'll see a number appear, that's the number of references in reference catalog. At the same time, your catalog length attrtibute will have been converted,
  15. open reference_catalog and updated by the same way as in previous catalogs updates

Thanx for help here: