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

Move notify for NewResponse for symmetry with other event exception h… #3702

Closed
wants to merge 2 commits into from

Conversation

ericatkin
Copy link
Contributor

…andling

@digitalresistor
Copy link
Member

@ericatkin could you provide some more context/colour around this change? As it stands now I am not sure what exactly this is changing, or what bug this is fixing.

How does that affect this diagram: https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/router.html?

@ericatkin
Copy link
Contributor Author

ericatkin commented Apr 13, 2022

This moves the NewResponse event to the Router.handle_request() method so that exceptions in such event handlers are treated in the same way as NewRequest, BeforeTraversal, and ContextFound (by tweens). As it is, I don't see any way to catch exceptions in NewResponse handlers. In my case, I want them handled by the excview_tween_factory, but it would allow custom tween authors to do something else if desired.

With regard to the diagram, it would move NewResonse above the egress tween node. I don't know how to update that.

@huntcsg
Copy link
Contributor

huntcsg commented May 23, 2022

@ericatkin The existing behavior is part of the documented public API. See the docs for pyramid.request.Request.add_response_callback:

All response callbacks are called after the tweens and before the pyramid.events.NewResponse event is sent.

Instead of making this change would you be able to register a tween at the correct position to accomplish whatever you are attempting to do in your NewResponse listener?

If that is impractical would it make sense to add an additional event/events that you could listen for instead of NewResponse?

@ericatkin
Copy link
Contributor Author

Yeah, now that I understand tweens, a tween under EXCVIEW works for me, but I found it surprising that NewResponse happens outside of the EXCVIEW tween as opposed to the other events. I imagine that would break a lot of code to move it as I proposed.
Thanks.

@ericatkin ericatkin closed this May 23, 2022
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

Successfully merging this pull request may close these issues.

3 participants