-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
fix(URI template): allow complex vars coexist with simple var #647
fix(URI template): allow complex vars coexist with simple var #647
Conversation
So |
e6e2d5a
to
336f7a1
Compare
Humm, actually, two remarks:
|
This was already the case before sorry. Is that on purpose, @kgriffs? |
OK, complex means also |
@yohanboniface Good point on the complex nodes conflicts! 👍 I think I have a simple way to detect such conflicts before we feed them to the compiled router. But perhaps in another pull-request. |
nodes = sorted(nodes, key=lambda node: node.is_var) | ||
# NOTE(kgriffs & philiptzou): Sort nodes in this sequence: | ||
# static nodes(0), complex var nodes(1) and simple var nodes(2). | ||
# so that none of them get masked. |
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.
@yohanboniface The registering order is not important since we'll sort the nodes inside our code. That's here. Before this case, static nodes (for example /foo/bar
) are always sorted before var nodes (/foo/{var}
).
So put '/compare/{file_id}'
after/before '/compare/{file_id}.{ext}'
are both acceptable and the results are the same.
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.
humm, but then this should work equally, right?
In [1]: from falcon.routing import DefaultRouter; router = DefaultRouter()
In [2]: router.add_route('/files/{file_id}', {}, 'xxxx2')
In [3]: router.add_route('/files/{file_id}.{ext}', {}, 'xxxx2')
In [1]: from falcon.routing import DefaultRouter; router = DefaultRouter()
In [2]: router.add_route('/files/{file_id}.{ext}', {}, 'xxxx2')
In [3]: router.add_route('/files/{file_id}', {}, 'xxxx2')
ValueError: The URI template for this route conflicts with another route's template.
Btw, I think we can simply detect conflicts amongst complex nodes like this: import re
def is_conflict(complex_nodes):
pseudo_segments = [re.sub(r'({[-_a-zA-Z0-9]+})', '{v}', n.raw_segment)
for n in complex_nodes]
return len(set(pseudo_segments)) < len(pseudo_segments)
|
@yohanboniface Good catch on the collision problem. See if the new revision I just submitted fix the issue you encountered. |
@philiptzou excellent! Your last commit fixes both collision issue and order issue :) @kgriffs LGTM |
(@philiptzou your should rebase the branch on master, github says there are conflicts ;) ) |
Have done the rebasing. |
a4278d3
to
b98715c
Compare
@philiptzou Nice work, LGTM! Could you please rebase once more and then I think this is ready to merge. |
Allow situation like this: ```python api.add_route('/files/{file_id}', resource_1) api.add_route('/files/{file_id}.{ext}', resource_2) ``` Which ValueError was raised due to only one var node was allowed whether other nodes are complex or not. This fix changes the behaviour so now it only applys to simple vars. See falconry#564
b98715c
to
32c8f22
Compare
@kgriffs Done :) |
@philiptzou Thanks! And thanks @yohanboniface for reviewing! |
…lex-var fix(URI template): allow complex vars coexist with simple var
Allow situation like this:
Which ValueError was raised due to only one var node was allowed whether
other nodes are complex or not. This fix changes the behaviour so now it
only applys to simple vars.
See #564