-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adding dict interface to Response may accidentally break "if response:" check #2772
Comments
I don't think we can do anything here. |
@asvetlov Yes, I mean maybe we should provide more warnings about this change, since this is just released a few days ago. Some old code may appear to be working except middle-ware return values are always discarded. It is bad because some middle-wares are doing security checks, if this change accidentally bypass the security check, there will be serious security issues. I think a special warning in the document and the next release note is necessary? |
The change is a part of aiohttp 3.0 release (2 weeks old). |
It looks like nothing could be done so I'm closing this. |
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. |
When solving #2246, a dict-like interface is added to Response (and StreamResponse). It is convenient, but there is a side effect: a response object was previous
True
, but now an empty response object isFalse
. This is quite surprising for developers who are not reading the documents carefully, so I think warnings should be added to document that these kind of objects must be tested withis None
.Considering this piece of code:
This piece of code call a middle ware, using its returning value as the final return value. If the middle_ware returns nothing, provides a default response.
But this breaks on 3.x because Response object is now a dict-like object, it contains a
__len__
method, so a newly created Response object is actuallyFalse
. The code must be modified to:The text was updated successfully, but these errors were encountered: