-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add a DuplicatedRulesError #3038
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
base: main
Are you sure you want to change the base?
Conversation
As from `tox -r -m update`
|
Looks good to me. It should resolve the problem I opened #3037 for. There are some cases with arguments involved that need to be considered. This does not raise an error: _ = r.Map(
[
r.Rule("/hello/<argument>", endpoint="hello"),
r.Rule("/hello/world", endpoint="hello_world"),
]
)but it seems that the second (more specific) rule always takes precedence over the first, regardless of the order they are added (at least in my quick testing). This makes sense and I think is intended behavior, so it should stay this way. This does raise an error: _ = r.Map(
[
r.Rule("/hello/<arg>", endpoint="hello_world"),
r.Rule("/hello/<arg>", endpoint="hello"),
]
)which is as expected. This does not raise an error: _ = r.Map(
[
r.Rule("/hello/<arg1>", endpoint="hello_world"),
r.Rule("/hello/<arg2>", endpoint="hello"),
]
)but it should do so, because there is no situation in which the second rule can be invoked. A possible solution would be to make argument names irrelevant in the check for the equality of rules (that is already modified in this pull request) werkzeug/src/werkzeug/routing/rules.py Lines 909 to 910 in 7868bef
My basic idea would be that __eq__ just sees /some/<>/url/<>/<>/with/arguments/<>, meaning that argument positions and the fact that arguments are used remains relevant, but not the internal names in the code (which seems to be the current behaviour).Not sure how though, I did not look close enough to understand what _trace does.
|
This is raised if an equivalent rule is added to the matcher to an existing rule. This should help users of the router know when they've accidentally duplicated a match.
|
Yep, I should have used |
|
Works perfectly now, thank you! I do not see further issues and would be happy if this is merged. |
This is raised if an equivalent rule is added to the matcher to an
existing rule. This should help users of the router know when they've
accidentally duplicated a match.