Comment 5 for bug 387487

Revision history for this message
Barry Warsaw (barry) wrote :

So, I'm having a very difficult time creating a lazr.restful test for this problem. I have a test case and a code fix for Launchpad, but I'm in a twisty maze of hurt trying to reproduce the problem in lazr.restful itself.

What I have so far: lp:~barry/lazr.restful.387487-subordinate

but it sucks :(

However, in src/lazr/restful/publisher.py, the following code fixes the
problem:

    def traverseName(self, request, ob, name):
        """See `zope.publisher.interfaces.IPublication`.

        In addition to the default traversal implementation, this publication
        also handles traversal to collection scoped into an entry.
        """
        # If this is the last traversal step, then look first for a scoped
        # collection. This is done because although Navigation handles
        # traversal to entries in a scoped collection, they don't usually
        # handle traversing to the scoped collection itself.
        if len(request.getTraversalStack()) == 0:
            try:
                entry = IEntry(ob)
            except TypeError:
                pass
            else:
                field = entry.schema.get(name)
                if ICollectionField.providedBy(field):
                    result = self._traverseToScopedCollection(
                        request, entry, field, name)
                    if result is not None:
                        return result
                elif IBytes.providedBy(field):
                    return self._traverseToByteStorage(
                        request, entry, field, name)
                elif IObject.providedBy(field):
                    sub_entry = getattr(entry, name, None)
                    if sub_entry is None:
                        raise NotFound(ob, name, request)
                    else:
                        return sub_entry
                elif field is not None:
                    return EntryField(entry, field, name)
                else:
                    # Falls through to our parent version.
                    pass
        return super(WebServicePublicationMixin, self).traverseName(
            request, ob, name)

Note the new goodness in the "elif IObject" stanza.