-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix StaticResource routes not resolving #12255
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
Open
BlindChickens
wants to merge
2
commits into
aio-libs:master
Choose a base branch
from
BlindChickens:fix_static_resource_routes_not_resolving
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fixed :py:class:`~aiohttp.web.StaticResource` not resolving urls when adding them via the internal ``_routes`` property. | ||
| You had to also add the method to the ``_allowed_methods`` property, which is not ideal. | ||
|
|
||
| Added :py:meth:`~aiohttp.web.AbstractResource.add_route` to :py:class:`~aiohttp.web.AbstractResource`. | ||
| -- by :user:`BlindChickens`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fixed :py:class:`~aiohttp.web.StaticResource` not resolving urls when adding them via the internal ``_routes`` property. | ||
| You had to also add the method to the ``_allowed_methods`` property, which is not ideal. | ||
|
|
||
| Added :py:meth:`~aiohttp.web.AbstractResource.add_route` to :py:class:`~aiohttp.web.AbstractResource`. | ||
| -- by :user:`BlindChickens`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, what is happening here?
It looks to me like you're trying to add a POST handler to a static resource. I can't understand how that makes any sense.
Can you please start by describing the issue you are supposedly fixing? Or the use case of this? As the documentation says, .add_static() is meant to emulate something similar to nginx static file handling, for use in local development only. Adding a POST handler makes no sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you are saying. The POST in the test case would be confusing. But there are other methods, so I can change it to something else, if that would help.
But to me it seems that you feel this cannot be useful because of this:
.add_static() is meant to emulate something similar to nginx static file handling.So if that's the case, then there is no use keeping this open.
If not, if I change the test case to add any other method handler through the new interface, would it be acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just don't understand what you're trying to achieve... A StaticResource should resolve to a file on the filesystem, why would you want to try adding a custom handler to it? It seems to me like you should be using a regular PlainResource through the router.add_post() etc. methods (https://docs.aiohttp.org/en/stable/web_reference.html#aiohttp.web.UrlDispatcher.add_routes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did this purely because we had a regression when updating past #9911, and when I investigated and saw that it also regressed something done in aiohttp-cors as indicated in the PR description of #9976.
So I was like, oh, they also want to add methods, let's fix that.
Our stuff that broke is obviously legacy shenanigans and we need to change it. But for now I just added an extra line:
self._allowed_methods.add("POST"), because you know stuff needs to keep moving.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I understand now. I think we probably want to reevaluate the aiohttp-cors integration before deciding that we want to add this to the public API. So, we'll probably avoid merging this PR currently until we have time to evaluate that properly.