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

Deprecate returning web.HTTPException from handlers and middlewares #2415

Closed
asvetlov opened this issue Oct 26, 2017 · 8 comments
Closed

Deprecate returning web.HTTPException from handlers and middlewares #2415

asvetlov opened this issue Oct 26, 2017 · 8 comments

Comments

@asvetlov
Copy link
Member

Now an endpoint might either return web.HTTPException (HTTPForbidden for example) or raise it.

It makes a mess, very often a middleware should check for type of response and process it as exception if the response is an instance of HTTPException.

Deprecation could be added just before this line: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_protocol.py#L428

Next step in transition plan is adding HTTPException.make_response() method.

At the end we could drop inheritance from web.Response at all.

@tailhook told me about the problem a year ago.
aiohttp.web was designed after Pyramid framework.
I still think Pyramid is much better designed than Django and Flask but the library is not such popular because alternatives acquired much better promotion.
Anyway, Pyramid inherits HTTP exceptions from both Response and Exception classes, we did the same.
Now, after years of working on aiohttp and derived projects, it's clean for me: the choice was definitely wrong.

I was not ready for such breaking change at the moment but now I have a strong feeling that the change makes sense and very important.

Sure, we should do transition smoothly: a warning and make_response() method could be added in next aiohttp 3.0 release but web.Response removal should wait for a year and half at least.

Champions for first two steps are welcome!

@asvetlov asvetlov added this to the 3.0 milestone Oct 26, 2017
@fafhrd91
Copy link
Member

I agree with motivation, but I think 1 year is too long. 3.0 should deprecate httpexception return. And turn to a hard error in half a year or 3.2

Replacing return with raise is not big change

@fafhrd91
Copy link
Member

Btw transition to 2.0 was not that hard, but amount of changes was relatively big.

@asvetlov
Copy link
Member Author

@fafhrd91 maybe you right. But maybe a year will be good enough. Or 1.5 years.
Honestly I don't care right now, we need to prepare for transition in aiohttp 3.0 and only after this date decide how long we should support deprecated logic.

@fafhrd91
Copy link
Member

I would even drop instead of deprecate for 3.0. migration to 3.0 would need attention to software in any case.

@kxepal
Copy link
Member

kxepal commented Oct 26, 2017

I'm +1 to drop as well.

@webknjaz
Copy link
Member

webknjaz commented Nov 9, 2017

+1 to drop inheritance from Response

@asvetlov
Copy link
Member Author

Fixed by #2515

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants