{"action":"created","issue":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/483","repository_url":"https://api.github.com/repos/marshmallow-code/marshmallow","labels_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/483/labels{/name}","comments_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/483/comments","events_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/483/events","html_url":"https://github.com/marshmallow-code/marshmallow/issues/483","id":162858347,"number":483,"title":"How to create a Schema containing a dict of nested Schema?","user":{"login":"lafrech","id":1767010,"avatar_url":"https://avatars.githubusercontent.com/u/1767010?v=3","gravatar_id":"","url":"https://api.github.com/users/lafrech","html_url":"https://github.com/lafrech","followers_url":"https://api.github.com/users/lafrech/followers","following_url":"https://api.github.com/users/lafrech/following{/other_user}","gists_url":"https://api.github.com/users/lafrech/gists{/gist_id}","starred_url":"https://api.github.com/users/lafrech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lafrech/subscriptions","organizations_url":"https://api.github.com/users/lafrech/orgs","repos_url":"https://api.github.com/users/lafrech/repos","events_url":"https://api.github.com/users/lafrech/events{/privacy}","received_events_url":"https://api.github.com/users/lafrech/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-06-29T07:26:49Z","updated_at":"2016-07-06T17:44:58Z","closed_at":null,"body":"Hi. I've been digging around and couldn't find the answer to this.\r\n\r\nSay I've got a model like this:\r\n\r\n```python\r\nclass AlbumSchema(Schema):\r\n    year = fields.Int()\r\n\r\nclass ArtistSchema(Schema):\r\n    name = fields.Str()\r\n    albums = ...\r\n```\r\n\r\nI want `albums` to be a `dict` of `AlbumSchema`, so that `ArtistSchema` serializes as\r\n\r\n```python\r\n{ 'albums': { 'Hunky Dory': {'year': 1971},\r\n              'The Man Who Sold the World': {'year': 1970}},\r\n  'name': 'David Bowie'}\r\n```\r\n\r\nNaively, I would expect syntaxes like this to work:\r\n\r\n```python\r\nfields.List(Schema)\r\nfields.Dict(Schema)\r\n```\r\nor maybe\r\n\r\n```python\r\nfields.List(fields.Nested(Schema))\r\nfields.Dict(fields.Nested(Schema))\r\n```\r\n\r\nSerializing a `list` of `Schema` can be achieved through `Nested(Schema, many=True)`, which I find less intuitive, and I don't know about a `dict` of `Schema`.\r\n\r\nIs there any way to do it? Or a good reason *not* to do it?\r\n\r\n(Question also [asked on SO](http://stackoverflow.com/questions/38048775/marshmallow-dict-of-nested-schema).)"},"comment":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/comments/230849761","html_url":"https://github.com/marshmallow-code/marshmallow/issues/483#issuecomment-230849761","issue_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/483","id":230849761,"user":{"login":"deckar01","id":3108007,"avatar_url":"https://avatars.githubusercontent.com/u/3108007?v=3","gravatar_id":"","url":"https://api.github.com/users/deckar01","html_url":"https://github.com/deckar01","followers_url":"https://api.github.com/users/deckar01/followers","following_url":"https://api.github.com/users/deckar01/following{/other_user}","gists_url":"https://api.github.com/users/deckar01/gists{/gist_id}","starred_url":"https://api.github.com/users/deckar01/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deckar01/subscriptions","organizations_url":"https://api.github.com/users/deckar01/orgs","repos_url":"https://api.github.com/users/deckar01/repos","events_url":"https://api.github.com/users/deckar01/events{/privacy}","received_events_url":"https://api.github.com/users/deckar01/received_events","type":"User","site_admin":false},"created_at":"2016-07-06T17:44:58Z","updated_at":"2016-07-06T17:44:58Z","body":"> Do you think it would make sense to add such a possibility to Marshmallow?\r\n\r\nIt seems like a reasonable feature to me.\r\n\r\nThe implementation may be more complex than the requirements make it sound though. Marshmallow is built on the assumption that homogeneous collections are lists.\r\n\r\nFor a `Nested` field to be able to handle a dictionary when `many=True`, the marshmallow core would need to be update to use the more generic iterable interface instead of the list interface.\r\n\r\nI am going to mull this over and make sure there is not a simpler solution I am overlooking."}}
{"actor":{"display_login":"deckar01"}}