-
Notifications
You must be signed in to change notification settings - Fork 1k
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
"Advanced : Nested Field" doc example is creating set() by mistake #513
Comments
Nice catch. It should really be something like: user_list_fields = {
'users': fields.List(fields.Nested(user_fields)),
} |
I don't know. I've played with it for some time. Even with
My understanding is that |
Try this instead? class UserList(Resource):
@marshal_with(user_list_fields)
def get(self):
return {'users': users.values()} you would nest the users list inside another object to be able to also return other metadata info with the response, such as pagination info. |
Thanks! It worked. Though, I had to wrap it in @marshal_with(user_list_fields)
def get(self):
return { 'users': list(users.values()), } Off-topic: It has to do with Py3's >>> d = {'a': 1, 'b': 2, }
>>> vs = d.values()
>>> vs
dict_values([2, 1])
>>> is_indexable_but_not_string(vs)
True
>>> vs[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dict_values' object does not support indexing
>>> |
The second data structure is actually a valid syntax for set().
Looking at the code for marshal(), the function would never work with set. Bombs-out on https://github.com/flask-restful/flask-restful/blob/master/flask_restful/__init__.py#L632
I don't know how to correct the example since this snippet works for me (marshaling list of user objects):
So I guess, better example is needed where Nested with List is really required.
The text was updated successfully, but these errors were encountered: