debugtoolbar - don't intercept a raised exception ?

11 views
Skip to first unread message

Jonathan Vanasco

unread,
May 21, 2021, 3:55:34 PM5/21/21
to pylons-discuss
One of my CI tests deals with an edge case, in which a HTTPMovedPermanently is raised in deeply nested code. This almost never gets raised in Production - rules on the loadbalancer/gateway typically catch it.

With the debugtoolbar off, Pyramid serves the redirect.  With the debugtoolbar enabled, it's caught by toolbar.py as an Exception and never makes it to the block of code dealing with `intercept_redirects`.

Has anyone encountered this before and developed a good workaround?  I feel like this test used to pass, but I can't find anything on our change history or Pyramid/Debugtoolbar's that would cause this change.


Jonathan Vanasco

unread,
May 25, 2021, 6:21:38 PM5/25/21
to pylons-discuss
I *temporarily* solved this by modifying an existing tween.  The relevant code looks like this:

    def my__tween(request):
        _redirect = None
        try:
            response = handler(request)
        except HTTPException as exc:
            _redirect = exc
        if _redirect:
            return _redirect
        return response

I'll likely migrate this to it's own tween for dev testing, unless I can figure out if the toolbar is loaded and run the code conditionally.  In any event, this approach lets me run my full test suite with the toolbar enabled.
Reply all
Reply to author
Forward
0 new messages