NameChooser in zope.app.container.contained sometimes doesn't choose a valid name and raises an exception

Bug #227617 reported by Christian Zagrodnick
4
Affects Status Importance Assigned to Milestone
Zope 3
Won't Fix
Medium
Christophe Combelles
zope.container
Fix Released
Medium
Christophe Combelles

Bug Description

The INameChooser interface isn't very explicit about chooseName's behaviour:

    def chooseName(name, object):
        """Choose a unique valid name for the object

        The given name and object may be taken into account when
        choosing the name.
        """

For me this reads: choose a name which I can use and never raise an exception. Currently chooseName can raise a UserError: "Names cannot begin with '+' or '@' or contain '/'"

I suggest letting chooseName remove + and @ at the beginning and replace / by - to prevent that and to generate a valid name.

Changed in zope3:
assignee: nobody → zagy
importance: Undecided → Low
Revision history for this message
Christophe Combelles (ccomb) wrote :

discussed here:
http://mail.zope.org/pipermail/zope3-dev/2007-October/024141.html
and here:
http://mail.zope.org/pipermail/zope-dev/2008-February/030920.html

I also believe that chooseName should just choose a name, and not raise an exception.

chooseName should be implemented so that it agrees with checkName: if checkName does not allow some characters, chooseName should remove these characters in the generated name.
And the INameChooser interface should talk about this failsafe behaviour.

Revision history for this message
Christophe Combelles (ccomb) wrote :

Attached is a suggested fix + tests. Please check and confirm.

Changed in zope3:
status: New → Confirmed
Revision history for this message
Christophe Combelles (ccomb) wrote :

commited in rev 87367

Changed in zope3:
status: Confirmed → Fix Committed
Revision history for this message
Christophe Combelles (ccomb) wrote :

released in zope.app.container 3.5.4

Changed in zope3:
assignee: zagy → ccomb
milestone: none → 3.4.0
status: Fix Committed → Fix Released
Revision history for this message
Christian Theune (ctheune) wrote :

That didn't work too well. We're now "vulnerable" to passing `None` as a parameter.

For one, this seems to not having had test coverage before your change, but it worked (one of our products relies on this). I'm willing to make the necessary changes if needed.

Changed in zope3:
importance: Low → Medium
status: Fix Released → Confirmed
Revision history for this message
Tres Seaver (tseaver) wrote :

The affected code now lives in zope.container.contained.

Changed in zope.container:
assignee: nobody → Christophe Combelles (ccomb)
importance: Undecided → Medium
status: New → Confirmed
Changed in zope3:
status: Confirmed → Won't Fix
Revision history for this message
Christophe Combelles (ccomb) wrote :

r111341
- chooseName now never fails if the suggested name is in the wrong type.
- checkName now checks the type first in checkName
- Convert most namechooser doctests into unittests
- Added more test cases

I'll backport into zope.app.container 3.5 and 3.6 maintenance branches

Changed in zope.container:
status: Confirmed → Fix Committed
Revision history for this message
Tres Seaver (tseaver) wrote :

Released today w/ zope.container 3.11.1:

  http://pypi.python.org/pypi/zope.container/3.11.1

Changed in zope.container:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.