Skip to content

Commit

Permalink
Fix AttributeError: query when running upgradeStep 1008
Browse files Browse the repository at this point in the history
  • Loading branch information
idgserpro authored and hvelarde committed Oct 13, 2020
1 parent f36fa24 commit 0cff52f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -12,6 +12,9 @@ There's a frood who really knows where his towel is.
This version removes tile registration/removal;
you must depend on plone.app.tiles >= 3.0.0 to avoid issues with ``collective.nitf`` tile.

- Fix AttributeError: query when running upgradeStep 1008 (fix `#226`_)
[idgserpro]

- Fix error when creating Plone Site, when collective.nitf is available (fix `#233`_).
[idgserpro]

Expand Down Expand Up @@ -256,4 +259,5 @@ There's a frood who really knows where his towel is.
.. _`#200`: https://github.com/collective/collective.nitf/issues/200
.. _`#205`: https://github.com/collective/collective.nitf/issues/205
.. _`#208`: https://github.com/collective/collective.nitf/issues/208
.. _`#226`: https://github.com/collective/collective.nitf/issues/226
.. _`#233`: https://github.com/collective/collective.nitf/issues/233
42 changes: 37 additions & 5 deletions src/collective/nitf/tests/test_upgrades.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from six.moves import range # noqa: I001
from collective.nitf.testing import DEXTERITY_ONLY
from collective.nitf.testing import INTEGRATION_TESTING
from collective.nitf.testing import IS_PLONE_5
from plone import api
from plone.dexterity.interfaces import IDexterityFTI
from plone.registry import field
from plone.registry.interfaces import IRegistry
from plone.registry.record import Record
from Products.CMFPlone.utils import safe_hasattr
from six.moves import range
from zope.component import getUtility

import unittest
Expand Down Expand Up @@ -79,6 +81,32 @@ def test_add_locking_behavior(self):
self.assertIn(locking_behavior, nitf.behaviors)


class to1008TestCase(UpgradeTestCaseBase):

def setUp(self):
UpgradeTestCaseBase.setUp(self, u'1007', u'1008')

def test_upgrade_to_1008_registrations(self):
version = self.setup.getLastVersionForProfile(self.profile_id)[0]
self.assertTrue(version >= self.to_version)
self.assertEqual(self.total_steps, 2)

def test_fix_collections(self):
title = u'Update existent collections'
step = self.get_upgrade_step(title)
self.assertIsNotNone(step)

with api.env.adopt_roles(['Manager']):
collection = api.content.create(self.portal, 'Collection', 'c1')

if DEXTERITY_ONLY:
self.assertFalse(safe_hasattr(collection, 'query'))

self.execute_upgrade_step(step)

self.assertTrue(safe_hasattr(collection, 'query'))


class to2000TestCase(UpgradeTestCaseBase):

def setUp(self):
Expand Down Expand Up @@ -242,8 +270,10 @@ def test_update_behaviors(self):

# run the upgrade step to validate the update
self.execute_upgrade_step(step)
self.assertIn('plone.app.relationfield.behavior.IRelatedItems', fti.behaviors)
self.assertIn('collective.nitf.behaviors.interfaces.ISection', fti.behaviors)
self.assertIn(
'plone.app.relationfield.behavior.IRelatedItems', fti.behaviors)
self.assertIn(
'collective.nitf.behaviors.interfaces.ISection', fti.behaviors)
self.assertIn(REFERENCEABLE, fti.behaviors) # should not be removed

def test_reindex_news_articles(self):
Expand All @@ -254,7 +284,8 @@ def test_reindex_news_articles(self):

with api.env.adopt_roles(['Manager']):
for i in range(0, 10):
api.content.create(self.portal, 'collective.nitf.content', str(i))
api.content.create(
self.portal, 'collective.nitf.content', str(i))

# break the catalog by deleting an object without notifying
self.portal._delObject('0', suppress_events=True)
Expand Down Expand Up @@ -325,7 +356,8 @@ def test_reindex_news_articles(self):

with api.env.adopt_roles(['Manager']):
for i in range(0, 10):
api.content.create(self.portal, 'collective.nitf.content', str(i))
api.content.create(
self.portal, 'collective.nitf.content', str(i))

# update metadata without notifying
self.portal['0'].subject = ('foo', 'bar')
Expand Down
7 changes: 7 additions & 0 deletions src/collective/nitf/upgrades/v1008/__init__.py
@@ -1,6 +1,7 @@
# -*- coding:utf-8 -*-
from collective.nitf.config import PROJECTNAME
from plone.app.upgrade.utils import loadMigrationProfile
from Products.CMFPlone.utils import safe_hasattr

import logging

Expand All @@ -22,6 +23,12 @@ def fix_collections(context):
try:
query = obj.getRawQuery() # Archetypes
except AttributeError:
# Empty Collections created with plone.app.contenttypes 1.0 and
# migrated to plone.app.contenttypes 1.1.x are missing the query
# attribute
if not safe_hasattr(obj, 'query'):
obj.query = []
continue
query = obj.getQuery() # Dexterity

if query is None:
Expand Down

0 comments on commit 0cff52f

Please sign in to comment.