-
Notifications
You must be signed in to change notification settings - Fork 889
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
Request.current_route_url drops _query #1040
Comments
I agree that qs = request.GET.copy()
qs.update({'page': 2})
request.current_route_url(_query=qs.items())
'http://example.com/fnord?id=23&page=2' |
It would very convenient for current_route_url were to encapsulate the merging. After all, that is the behavior of the matchdict arguments, and it seems to me this covers how the function is currently used. If needed, the replace behavior could be exposed with another argument. |
Likewise, a custom port number will be dropped. |
@merwork What do you mean by a custom port number? I haven't found that |
I mean non-default: if you run with waitress on port 6543 for example, route_url will generate http://localhost/etc (I’ll need to check with latest pyramid, and also current_route_url vs. route_url) |
Neither |
The port number issue sounds like a case of not properly forwarding information to the wsgi environ from your reverse proxy. This is a classic issue with https, port numbers and path prefixes behind reverse proxies. |
Currently, request.current_route_url strips the query string. Passing it the _query parameter overrides the default behavior which is inconsistent. An option would be to have an extra parameter _with_current_qs which would allow for: This would not break backward compatibility and would provide the options. However, it is not very intuitive and should be properly documented. Or we could make |
Or the behaviour could be changed to return by default the query string and pass _query=None if you want nothing (current behaviour), and pass {a=b} if you want to override the values in the query string. |
The merging operation is unintuitive for the query string because you can specify each parameter more than once which is valid in HTTP and the reason the items = [('q', '1'), ('q', '2')]
url = request.route_url('foo', _query=items) # -> http://example.com/foo?q=1&q=2 To me the things to do in this situation are:
The override option could be done by telling the user to just use To me the sane option is still to just override the whole query string if specified. |
So should we provide a _with_query = True/False flag for people that -want- the query string included? |
@mmerickel You're right about the sane option of overriding the whole query string. How's about request.current_url returning the query string? Should it be the default behaviour or like @jeffszusz proposes to pass a new param? To me it seems expected that the returned url should contains the query string, like request.url, but it breaks up bw compatibility. |
I think it's a bug that the current |
I'm +1 on this, lets see what @mcdonc thinks :) |
+1 :) |
I agree it's a bug and should be fixed. |
👍 |
1 similar comment
+1 |
Fixed via #1081. In the future if a real merge operation is desired this can probably be done via some boolean flag to |
Request.current_route_url is an easy way to generate the current route, but add/update a few parameters. This works fine for elements in the matchdict, but not at all for _query parameters. I know they're very 1990's, but they are still useful for optional filters, etc.
Expected behavior would be:
URI = "http://example.com/fnord?id=23"
Current behavior:
The text was updated successfully, but these errors were encountered: