Fix misuse of class field for handling of base args #165
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.
Views can have a
route_base
, which can contain parameters (e.g.route_base = /foo/<bar>
). Such parameters are given as arguments to the methods of the view. When generating routing rules for the method of such a view, the argument(s) of the method corresponding to the parameter(s) of theroute_base
should be ignored for the purpose of generating routing rules.This is currently done by discovering such parameters when parsing
route_base
, and adding the discovered parameters to abase_args
list bound directly to the class. However, the class argument is declared at the level ofFlaskView
. I realized that when subclassing it multiple times withroute_base
containing parameters, the list containing the parameters is shared by all subclasses. Thus, previously discovered parameters have an influence on all subsequently registered view methods and cause erroneous routing rules being generated, for example with the following:Here,
bar
inFooShallowView
would be ignored due tobar
being inbase_args
after registeringFooDeepView
. The expectedGET /foo/<bar> -> FooShallowView.get
routing rule would be incorrectly generated asGET /foo -> FooShallowView.get
sincebar
is ignored. Then,GET /foo/whatever
ends up with a 404 since no routing rule correspond to this path.It's relatively straightforward to fix though, by removing
base_args
at the level of the class, and simply returning the discovered parameters along with theroute_base
inget_route_base
and appending the returned parameters to the ignored arguments.base_args
is not used elsewhere and is not directly used by users.I also adjusted
test_base_args
to focus on simply testing the behavior ofroute_base
with parameters.