grouping directives do not accomodate certain attributes in directive schemas

Bug #274655 reported by Devin
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zope 3
Won't Fix
Undecided
Unassigned
zope.configuration
Won't Fix
Undecided
Unassigned

Bug Description

Adding an attribute to a grouping directive's schema that is directly accessed by `zope.configuration.config.GroupingStackItem` using its 'context' member variable exposes a bug in the configuration machinery. There are two attributes that I know of that are problematic ('action', 'factory'), but members of `zope.configuration.config.ConfigurationMachine` (and its superclasses) could be suspect as well.

Attached is a sample traceback from 'transcript.log' that occurred when I attempted to use the 'factory' attribute for one of my custom grouping directives.

Note that the last line in the traceback:

    ZopeXMLConfigurationError: File "/var/lib/zope3/instance/sandbox/lib/python/powersite/browser/configure.zcml", line 20.4

... refers to the first subdirective of the directive that contains the factory attribute. The subdirective is also registered as a grouping directive.

I believe that the intended 'factory' attribute is the 'factory' method of `zope.configuration.configure.ConfigurationAdapterRegistry`.

I've read that complex directives will eventually be deprecated in favor of grouping directives. If that's true, then this change will need to be made for complex directives that currently have a `factory` or `action` attribute.

Revision history for this message
Devin (devin.charityfinders.org) wrote :
Revision history for this message
Devin (devin.charityfinders.org) wrote :

Also, if the grouping directive you create doesn't subclass `zope.configuration.config.GroupingContextDecorator` and/or doesn't have similar '__getattr__' functionality (and still satisfies the interface contract of `zope.configuration.interfaces.IGroupingContext`), then Zope will terminate with an AttributeError message complaining about the lack of a 'factory' attribute.

Instead of attempting to find the needed methods on its 'context' member, perhaps the various stack item class instances should find the objects with the methods they need by searching up the tree until an object that implements `zope.configuration.interfaces.IConfigurationContext` is found. Something like:

    def __getConfigurationContext(self):
        context = self.context
        while not IConfigurationContext.implementedBy(context):
            context = context.context
        return context

... and replacing `self.context` with `self.__getConfigurationContext()` (where appropriate) should work (I haven't tested it), and would still allow grouping directives to contain attributes like 'action' and 'factory'.

Revision history for this message
Devin (devin.charityfinders.org) wrote :

I logged in to check if anyone has handled this bug, and realize that I should have written 'providedBy' where I wrote 'implementedBy'.

Revision history for this message
Devin (devin.charityfinders.org) wrote :

It's been nearly a year since I filed this bug, and nothing has changed.

Revision history for this message
Patrick Gerken (do3cc) wrote :

Can you provide a working example?

Revision history for this message
Devin (devin.charityfinders.org) wrote :

I can provide a simple example that demonstrates the bug (attached). Here's the result of running the example from the command line:

devin@development:~/temporary$ python2.5 demo.py
Traceback (most recent call last):
  File "demo.py", line 66, in <module>
    main()
  File "demo.py", line 63, in main
    string(_CONFIG)
  File "/usr/lib/python2.5/site-packages/zope/configuration/xmlconfig.py", line 627, in string
    processxmlfile(f, context)
  File "/usr/lib/python2.5/site-packages/zope/configuration/xmlconfig.py", line 378, in processxmlfile
    parser.parse(src)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 207, in feed
    self._parser.Parse(data, isFinal)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 338, in start_element_ns
    AttributesNSImpl(newattrs, qnames))
  File "/usr/lib/python2.5/site-packages/zope/configuration/xmlconfig.py", line 230, in startElementNS
    self.context.begin(name, data, info)
  File "/usr/lib/python2.5/site-packages/zope/configuration/config.py", line 539, in begin
    self.stack.append(self.stack[-1].contained(__name, __data, __info))
  File "/usr/lib/python2.5/site-packages/zope/configuration/config.py", line 840, in contained
    return RootStackItem.contained(self, name, data, info)
  File "/usr/lib/python2.5/site-packages/zope/configuration/config.py", line 708, in contained
    factory = self.context.factory(self.context, name)
  File "demo.py", line 37, in __call__
    raise Exception("You rang?")
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "<string>", line 20.6
    Exception: You rang?

The Zope package is the Zope 3.4 package from Ubuntu's stable 9.04 repository.

Revision history for this message
Devin (devin.charityfinders.org) wrote :
Tres Seaver (tseaver)
Changed in zope3:
status: New → Won't Fix
Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in zope.configuration:
status: New → Won't Fix
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.