2012/05/25

Plone Undocumented Content Rules Limit

One of my Plone instances has around 100 content rules added, and then hit by an error:

... ...
 Module plone.app.contentrules.namechooser, line 30, in chooseName
 Module zope.container.contained, line 761, in checkName
KeyError: u'The given name is already being used'

From #plone channel, @MacYET tells me to use PDB. Here is the info log:

> /opt/myplone/buildout-cache/eggs/zope.container-3.8.2-py2.6-linux-i686.egg
 /zope/container/contained.py(761)checkName()
-> raise KeyError(
(Pdb) dir()
['name', 'object', 'pdb', 'reserved', 'self']
(Pdb) pp name
u'rule-101'
(Pdb) pp self
<plone.app.contentrules.namechooser.RuleNameChooser object at 0x10a33c6c>
(Pdb) pp self.context
<plone.contentrules.engine.storage.RuleStorage object at 0x10c2f0ac>
(Pdb) pp self.context.__dict__
{'_data': <BTrees.OOBTree.OOBTree object at 0xd97238c>,
 '_order': ['rule-1', ... ... 'rule-99', 'rule-100', 'rule-101']}

In plone/app/contentrules/namechooser.py:

ATTEMPTS = 100


class RuleNameChooser(NameChooser):
    """A name chooser for content rules.
    """

    implements(INameChooser)

    def __init__(self, context):
        self.context = context

    def chooseName(self, name, object):
        container = self.context

        if not name:
            name = object.__class__.__name__.lower()

        i = 1
        new_name = "%s-%d" % (name, i)
        while new_name in container and i <= ATTEMPTS:
            i += 1
            new_name = "%s-%d" % (name, i)

        self.checkName(new_name, object)
        return new_name

I can accept this is not a bug, but a documentation should be helpful.

No comments: