Support rule arguments in route_base #20
Merged
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.
This pull request maybe should have been two. First, it fixes the behaviour of the arguments passed to the proxied views:
As far as I can tell, Flask always calls views with only a
**<dict>
, so we can drop*args
altogether there unless I'm missing something. Maybe strange use cases of people calling view functions manually? I'll put them back if you think it's an issue. The place where Flask calls view functions seems to be centralized to always go through this line in flask.app.The dict that is passed is the one from the global request object. From my own testing with flask's built-in
@before_request
method, it seems you can change therequest.view_args
dict in a@before_request
, and expect the arguments passed to views to be changed accordingly.The flask-classy proxy, however, was getting passed
**request.view_args
by flask, and then passing that into the class'sbefore_request
,before_<method>
, and finally the actualview
method, which means it could not be modified.I'm going on a lot here, and it might seem like a pretty weird use-case, but I wanted to be able to have the modified
request.view_args
passed to my view methods so that I could pull out arguments fromcls.route_base
first. Which leads me to....Support for arguments in
cls.route_base
! I wanted to do class-level pre-processing of arguments inroute_base
, which lead to all kinds of problems before. The main issue was that adding theroute_base
argument to my view's method declaration caused the variable to be added to the rule twice, and making werkzeug throw a -fit-ValueError
.So I pulled in
werkzeug.routing.parse_rule
to find any rules in theroute_base
which should not be re-added because of a method declaration, and had them be ignored along withself
inbuild_rules
.I added some tests which I think cover my changes. Seems to be working fine for me so far. Let me know what you think!