Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zope.browserpage.metaconfigure.simple breaks subpaths #6

Open
vincg opened this issue May 16, 2019 · 8 comments
Open

zope.browserpage.metaconfigure.simple breaks subpaths #6

vincg opened this issue May 16, 2019 · 8 comments

Comments

@vincg
Copy link

vincg commented May 16, 2019

I'm currently in the process of porting a Zope2 project to Zope4, which worked surprisingly well so far. One big issue I've come across though is that our subpaths are broken, due to the simple-Class overriding our own publishTraverse and always returning NotFound.

our implementation

@implementer(IPublishTraverse)
class BaseSubPathView(object):
    def __init__(self, *a, **k): [...]
    def publishTraverse(self, request, name): [...]
    def __call__(self): [...]

and in zope.browserpage.metaconfigure

@implementer(IBrowserPublisher)
class simple(BrowserView):
 
    def publishTraverse(self, request, name):
        raise NotFound(self, name, request)

    def __call__(self, *w, **k): [...]

This does not work anymore because simple.publishTraverse is used, not BaseSubPathView.publishTraverse ... I patched this locally to the following:

@implementer(IBrowserPublisher)
class simple(BrowserView):

    def publishTraverse(self, request, name):
        # check if this method was overridden somewhere down the mro
        for c in self.__class__.__mro__[1:]:
            meth = getattr(c, 'publishTraverse', None)
            if meth is not None:
                return meth(self, request, name)
        raise NotFound(self, name, request)

    def __call__(self, *w, **k): [...]
@icemac
Copy link
Member

icemac commented May 16, 2019

zope.browserpage is also used outside Zope 4, so I'd rather like to fix this issue over there. See zopefoundation/Zope#610 for a PR which is work in progress.

@icemac
Copy link
Member

icemac commented Jun 18, 2019

@vincg Does #7 fix your problem?

@icemac
Copy link
Member

icemac commented Jun 18, 2019

#7 is released in version 4.4.0 on PyPI.

@vincg
Copy link
Author

vincg commented Jun 20, 2019

@icemac looks good! thanks for letting me know!

@icemac
Copy link
Member

icemac commented Jun 21, 2019

According to @vincg fixed via #7.

@icemac icemac closed this as completed Jun 21, 2019
@vincg
Copy link
Author

vincg commented Jun 24, 2019

It seems I was a bit hasty in testing this. I did install it in the right virtualenv and followed our manual testcase and it worked, yet it did not verify the updated package was actually being used.

so it does not work yet. maybe this can be fixed in our code, I'm not sure and have to do more research, since this part of our application is rather old and the original dev is not with us anymore. I'm going to go into more detail on our subpathview, if that helps.

@implementer(IPublishTraverse)
class BaseSubPathView(object):

    def __init__(self, *args, **kw):
        self.subpaths = {}
        self._called_sub_path = None
        # find subpaths and bild up lookup
        for m_name, m in inspect.getmembers(self, predicate=inspect.ismethod):
            if hasattr(m, '_sub_path_name'):
                self.subpaths[m._sub_path_name] = m

    def publishTraverse(self, request, name):
        ''' Lookup for subpath
            (zope.publisher.interfaces.IPublishTraverse)
        '''
        log.debug('sub traverse %s' % name)
        if name in self.subpaths:
            self._called_sub_path = self.subpaths[name]
            return self
        return request.response.notFoundError(name)

    def __call__(self):
        csp = self._called_sub_path
        return csp() if csp else None

@icemac icemac reopened this Jun 25, 2019
@icemac icemac removed their assignment Sep 24, 2020
@icemac
Copy link
Member

icemac commented Sep 24, 2020

Are there any news on this issue?

@vincg
Copy link
Author

vincg commented Oct 8, 2020

from "our" side I don't know, I don't work for this company anymore, but my guess is my "patch" is still in use and it's not a priority as long as it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants