cast query string keys/values to string before passing to quote()#6099
Conversation
|
@chris48s thanks for this. It was discussed in the dev meeting that rather than cast everything to |
|
Presumably the numeric case should also cast to string. |
|
Yes, sorry. Numbers should be supported |
324114f to
42c1278
Compare
| if value is None: | ||
| return 'null' | ||
| if isinstance(value, numbers.Number): | ||
| return str(value) |
There was a problem hiding this comment.
To keep with the JSON style null:
| return str(value) | |
| return str(value).lower() # render True/False as true/false |
There was a problem hiding this comment.
Having churned this over slightly more over the weekend, it seems to me that really in this fallback case except FlaskRouteBuildError: we should really be trying to match the behaviour of named routes as closely as possible.
i.e: what we should be aiming for is that
h.url_for("dataset.read", id="my_dataset", somebool=True) and
h.url_for("/dataset/my_dataset", somebool=True)
should do the same thing, as should
h.url_for("dataset.read", id="my_dataset", empty=None) and
h.url_for("/dataset/my_dataset", empty=None)
etc
FWIW:
h.url_for("dataset.read", id="my_dataset", param=True) == '/dataset/my_dataset?param=True'
h.url_for("dataset.read", id="my_dataset", param=None) == '/dataset/my_dataset'
h.url_for("dataset.read", id="my_dataset", param={}) == '/dataset/my_dataset?param=%7B%7D'
Shall I alter it so the fallback matches the named route behaviour? @amercader @wardi ? It seems the most logical on reflection.
There was a problem hiding this comment.
Yes, @chris48s this makes sense. It's good to have url_for having a consistent output regardless of how it is invoked
There was a problem hiding this comment.
OK. I've updated to implement that behaviour
|
Thanks @chris48s Just so it's clear as I was confused by this. In this PR we are sticking with from flask import url_for
url_for('home.about', some_param='cat', another=True, dogs=[], rabbits=None)
# '/about?some_param=cat&another=True'And in this PR we are just fixing our fallback code for when Flask can't build a URL, eg because we are using the deprecated Does that sound good @wardi ? |
|
@amercader sounds good |
|
Just to flag, I think this PR should be backported to the next 2.9 release (it is a bugfix not a feature) but it doesn't have the "Backport 2.9.4" label applied to it. |
Proposed fixes:
Cast query string keys/values to string before passing to
quote()This issue can cause us to throw
AttributeError: 'bool' object has no attribute 'rstrip'calling something likeI've been hitting this problem on CKAN 2.9 so this should definitely be backported to 2.9. It might also be applicable to 2.8.
Features: