-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Improve documentation on fields.DelimitedList vs fields.List #406
Comments
The current behavior appears correct: >>> f = fields.DelimitedList(fields.Int())
>>> f.deserialize([42,24])
Out[2]: [42, 24]
>>> f.deserialize('42,24')
Out[3]: [42, 24] Can you post code to reproduce your issue? |
Creating a small reproducible example is going to take a while. Here's a small example though: class MySchema(marshmallow.Schema):
stages = webargs.fields.DelimitedList(webargs.fields.Str()) When I hit an endpoint that uses this schema, like this: If I change my implementation to use I managed to create custom marshmallow field that's almost the same as the implementation for DelimitedList and got it working as expected end to end. |
It's very possible that this implementation is broken due to something specific to my current application. The fix that worked for me is extremely puzzling and I cannot for the life of me figure out why this is breaking it. Changing the field |
Ah I see, you're parsing query params. |
Gotcha, I feel we should change the docs then because the docs say this should operate exactly like marshmallow.fields.List but that’s not true. |
I’ll stick with my custom implantation. Since apis and libraries are inconsistent, I wanted a solution that would support both list types. |
I agree that the docs can make this clearer. The docstring for Perhaps we could add "Delimited Lists" section to the Quickstart. |
This is just a suggestion but perhaps we should change the function doc from I do just have one last question though, in your example above
When would we ever hit the case |
Well, the field itself does load either a list or delimited string. However, webargs will transparently handle MultiDicts like Lines 116 to 117 in 23dfd6f
It will also skip that logic for non-MultiDict types, e.g. |
If we're always expecting DelimitedList to handle the deserialization of a single value, why have it extend marshmallow.fields.List? Why not just marshmallow.fields.Field? |
Also, this explains the super confusing behavior I was talking about above. Anything that extends marshmallow.fields.List and has a property Line 68 in 23dfd6f
|
Conceptually,
Yeah..I don't recall why we decided to use duck-typing here. At the very least, it hurts readability. At worst, it leads to unexpected behavior like you ran into. I'll change this. |
5.4.0 removes the duck typing . I also added more docs re: parsing lists in query strings: https://webargs.readthedocs.io/en/latest/quickstart.html#parsing-lists-in-query-strings . |
The docs for the fields.DelimitedList say it "can load from either a list or a delimited string" but I cannot get it to load from a list.
It's possible I'm doing something wrong
but When I swap outfields.DelimitedList
forfields.List
everything works as expected. I think either the docs should be changed, or we should fix the implementation ofDelimitedList
so that it works as expected.The text was updated successfully, but these errors were encountered: