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
Url conflict assert #1568
Url conflict assert #1568
Conversation
I think all these commits could be easily squashed into a single one. |
Done, everything was squashed down to that one commit. |
I think you have some leftovers from failed merges with upstream in there. Check the diff and remove anything that's not actually related to your PR (and maybe try to switch to a <=51-char first line in the commit message when committing it again) |
@@ -1029,6 +1029,27 @@ def index(): | |||
rule = self.url_rule_class(rule, methods=methods, **options) | |||
rule.provide_automatic_options = provide_automatic_options | |||
|
|||
for prior_rule in self.url_map.iter_rules(): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
I rebased against master and re-added my changes. Looks like I missed a couple of wonky space changes, in |
The last commit was to add some in-line comments that got dropped when I re-added the changes. |
prior_rule_methods = self.prior_rules.get( | ||
prior_rule_check, | ||
None) | ||
# Flask adds non-specified methods to routes. Removing the |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
In principle I support a mechanism that detects and prevents shadowing of other
URL rules, but this implementation isn't acceptable due to a few reasons:
- The static path is hardcoded for some special casing
- `prior_rules` will only be updated if the app registers its routes the
"normal" way. It is possible for those two datastructures to get out of sync
when the app dev modifies them directly, which is still practiced sometimes.
- Unrelated code reformatting, not a minimal diff
…On Mon, Apr 24, 2017 at 10:25:06AM -0700, David Lord wrote:
@davidism requested your review on: pallets/flask#1568 Url conflict assert.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1568 (comment)
|
I will just close this since it's also unclear to me how a better implementation could look like. |
Probably a "better implementation" should be in Werkzeug, not in Flask. i.e. fail when adding a conflicting rule to a url map |
This PR is an attempt to reconcile the fact that you can't have two routes with the same function name but you can create two routes with the same URL.
will throw an
AssertionError
but
wont. In fact the second route is unreachable.
This PR checks to see if three conditions are true before raising an assertion. The new rule has to have a
subdomain
,url_path
, and onemethod
that overlap with a current rule in theself.url_map object
.There's a couple of wonky pieces in this pull request that were required to get all of the unit tests to pass.
was required to get blueprints to not throw an assertion since each blueprint registers a
"/static/<path:filename>"
rule for each blueprint. I tried to find a way to not have to use a static string but alas I failed.Secondly
is used to check for all explicitly registered methods for a route since there were a bunch of cases where the
OPTIONS
method was implicitly added to rules that shared a url_path.This change is