hug
hug copied to clipboard
Regardless of type, Hug first serializes arguments into comma separated list
Not sure if I'm missing something but I first found this issue when trying to use delimited_list. No matter what pipe delimited query string I gave it, it wasn't validating it correctly. This was quite strange as when I tested out delimited_list('|') by itself with various arguments, it returned expected results.
I did some debugging and noticed that even if I don't use a validator at all (I expect to get no conversions of any kind in this case), I get back a comma separated list if I give it an argument with commas. It seems that before the argument even gets validated, it's already being converted into a list somehow.
+1 on this issue and I'm sad to see there's been no movement on this. No matter what kind of type validator I use, it always interprets a string with commas as a list, which is very problematic. I've tried hug.types.text
, str
and a string description. None behave as I would expect.
Commas are a reserved character in HTTP URL requests, and as such if you are able to escape them, I believe this is best practice. Due to their official reserved nature, at some point Falcon changed the default handling of commas to turn them into a List the same as parameters that are defined multiple times. However even they have reverted that behaviour back to what both you have expected - but Hug has kept the old behaviour simply not to break backward compatibility a second time. However, you should still be able to do what you want by changing this default setting in your API:
@hug.startup()
def init_settings(api):
api.http.falcon.req_options.auto_parse_qs_csv = False
Note that this change, along with a few other default parameter changes are scheduled to be made live in Hug 3.0.0 by default.
I hope this is helpful, and I'm sorry this has effected you!
~Timothy
@timothycrosley Thanks for the quick response. That snippet worked for me!
So glad to hear!
Thanks @timothycrosley that worked for me as well!
Since Falcon supports the multiple parameter definitions form of accepting a list from query params, does that package also have a recommended way to represent a list of one item?
When running some tests using auto_parse_qs_csv
set to false, it seems impossible to send a single item list - the single items are always interpreted as string types.
The user submitted issue 719 is about how to send a list of one item to the query params. These 2 issues seem related, yet they have different requirements for auto_parse_qs_csv
.
@DaveTrost Is it different than the documented behavior described here?
For auto_parse_qs_csv=False
, /?t=1,2,3&t=4
would render to ['1,2,3', '4']
. Is the issue that /?t=1,2,3
renders to '1,2,3'
, i.e. not contained in a list?
The Falcon docs don't seem to specify behavior for a single element list with the False setting, but it would be reasonable to expect that a single item is formatted into a list in both the False/True cases.