collective / collective.nitf

A Dexterity-based content type inspired on the News Industry Text Format specification
8 stars 3 forks source link

AttributeError: query when running upgradeStep 1008 #226

Closed idgserpro closed 4 years ago

idgserpro commented 5 years ago

This is a really specific case and since I don't know this is going to be fixed (since it's too specific and old) I'm opening this issue to document the traceback if someone is upgrading from old installations since there's an workaround.

When upgrading a brasil.gov.portal instance, from 1.0.5 to 1.5.3, plone.app.contenttypes goes from 1.0 to 1.1.1 and collective.nitf from 1.0b3 to 2.1b4.

If you created an empty collection when plone.app.contenttypes was 1.0, and upgrade it afterwards, and run upgradeStep 1008 from collective.nitf, you get:

Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module Products.GenericSetup.tool, line 1053, in manage_doUpgrades
Module Products.GenericSetup.upgrade, line 166, in doStep
Module collective.nitf.upgrades.v1008, line 25, in fix_collections (https://github.com/collective/collective.nitf/blob/2.1b4/src/collective/nitf/upgrades/v1008/__init__.py#L25)
Module plone.app.contenttypes.content, line 45, in getQuery (https://github.com/plone/plone.app.contenttypes/blob/1.1.6/plone/app/contenttypes/content.py#L45)
AttributeError: query

If you have an old installation with collective.nitf 1.0b3, plone.app.contenttypes 1.0 and update to collective.nitf 2.1b4, and plone.app.contenttypes to 1.1.6, when running the upgradeStep, you get the same error. I've attached two .cfgs, one for 1.0b3 and another for 2.1b4 to recreate the instances in these versions. cfgs.zip

Workaround: you can create a Python Scrip in the ZMI to list these problematic collections and delete them, This way, you can run the upgradeStep again:

collections = context.portal_catalog(portal_type='Collection')  # NOQA
colecoes_vazias = []
for col in collections:
    obj = col.getObject()
    try:
        query = obj.getRawQuery()  # Archetypes
    except AttributeError:
        try:
            query = obj.getQuery()
        except AttributeError:
            colecoes_vazias.append(obj)

if colecoes_vazias:
    print "Empty collections:"
    for i in colecoes_vazias:
        print i.absolute_url()
else:
    print "No empty collections."

return printed  # NOQA

(Possibly related: https://github.com/collective/collective.nitf/commit/0fef6227868d9f1c25177af2b589a36caf1759ed)

idgserpro commented 4 years ago

When we try to edit an empty collection that came from migrating from plone.app.contenttypes 1.0 to 1.1.1, we get the error:

2020-02-20 21:07:26 ERROR Zope.SiteErrorLog 1582243646.290.316684863924 http://localhost:8080/Plone/colecao-vazia/@@edit
Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 66, in __call__
  Module plone.z3cform.layout, line 50, in update
  Module plone.dexterity.browser.edit, line 64, in update
  Module plone.z3cform.fieldsets.extensible, line 59, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 132, in update
  Module z3c.form.form, line 136, in updateWidgets
  Module z3c.form.field, line 277, in update
  Module Products.CMFPlone.patches.z3c_form, line 46, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module plone.formwidget.querystring.converter, line 33, in toWidgetValue
TypeError: 'NoneType' object is not iterable

So just ignoring these collections isn't a good option.