{"action":"created","issue":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/319","repository_url":"https://api.github.com/repos/marshmallow-code/marshmallow","labels_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/319/labels{/name}","comments_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/319/comments","events_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/319/events","html_url":"https://github.com/marshmallow-code/marshmallow/issues/319","id":114860922,"number":319,"title":"Nested field with many=True and required=True gives unexpected error for missing data","user":{"login":"chekunkov","id":744331,"avatar_url":"https://avatars3.githubusercontent.com/u/744331?v=4","gravatar_id":"","url":"https://api.github.com/users/chekunkov","html_url":"https://github.com/chekunkov","followers_url":"https://api.github.com/users/chekunkov/followers","following_url":"https://api.github.com/users/chekunkov/following{/other_user}","gists_url":"https://api.github.com/users/chekunkov/gists{/gist_id}","starred_url":"https://api.github.com/users/chekunkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chekunkov/subscriptions","organizations_url":"https://api.github.com/users/chekunkov/orgs","repos_url":"https://api.github.com/users/chekunkov/repos","events_url":"https://api.github.com/users/chekunkov/events{/privacy}","received_events_url":"https://api.github.com/users/chekunkov/received_events","type":"User","site_admin":false},"labels":[{"id":260913230,"url":"https://api.github.com/repos/marshmallow-code/marshmallow/labels/backwards%20incompat","name":"backwards incompat","color":"eb6420","default":false},{"id":96590028,"url":"https://api.github.com/repos/marshmallow-code/marshmallow/labels/feedback%20welcome","name":"feedback welcome","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/milestones/10","html_url":"https://github.com/marshmallow-code/marshmallow/milestone/10","labels_url":"https://api.github.com/repos/marshmallow-code/marshmallow/milestones/10/labels","id":1419130,"number":10,"title":"3.0","description":"","creator":{"login":"sloria","id":2379650,"avatar_url":"https://avatars2.githubusercontent.com/u/2379650?v=4","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":13,"state":"open","created_at":"2015-11-19T03:17:00Z","updated_at":"2018-03-07T00:33:56Z","due_on":null,"closed_at":null},"comments":15,"created_at":"2015-11-03T16:57:23Z","updated_at":"2018-03-18T18:03:28Z","closed_at":null,"author_association":"NONE","body":"Say I have following schema definition\n\n``` python\nfrom marshmallow import Schema, fields\n\n\nclass ObjectSchema(Schema):\n    id = fields.Integer(required=True)\n    name = fields.String(required=True)\n\n\nclass CollectionSchema(Schema):\n    data = fields.Nested(ObjectSchema, many=True, required=True)\n```\n\nHere's how this schema works for several invalid inputs\n\n```\nIn [6]: CollectionSchema().load({})\nOut[6]: UnmarshalResult(data={}, errors={'data': {0: {'name': ['Missing data for required field.'], 'id': ['Missing data for required field.']}}})\n\nIn [7]: CollectionSchema().load({'data': []})\nOut[7]: UnmarshalResult(data={'data': []}, errors={})\n\nIn [8]: CollectionSchema().load({'data': [{}]})\nOut[8]: UnmarshalResult(data={'data': [{}]}, errors={'data': {0: {'name': ['Missing data for required field.'], 'id': ['Missing data for required field.']}}})\n```\n\nIMO `Out[8]` is the only correct validation error from the examples - it correctly describes the problem - all required fields are missing in nested item. For other examples I actually expect something like:\n\n1. \n\n```\nIn [6]: CollectionSchema().load({})\nOut[6]: UnmarshalResult(data={}, errors={'data': ['Missing data for required field.']})\n```\n\nshows that 'data' field is required and missing. I'm missing this one badly.\n\n2.\n\n```\nIn [7]: CollectionSchema().load({'data': []})\nOut[7]: UnmarshalResult(data={'data': []}, errors={'data': ['Field may not be empty list.']})\n```\n\nshows that field contains empty list - for my usecase it's the same as missing field. Well, this one is arguable, maybe `Nested` field requires another parameter to enforce validation errors in case of empty nested value.\n\nSo currently marshmallow cannot distinguish between these three cases which complicates automated error handling in JSON api I'm working on now - as I said errors do not describe the problem properly. What do you think - is it an issue or I'm missing something and there's better approach to this problem?\n"},"comment":{"url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/comments/374024567","html_url":"https://github.com/marshmallow-code/marshmallow/issues/319#issuecomment-374024567","issue_url":"https://api.github.com/repos/marshmallow-code/marshmallow/issues/319","id":374024567,"user":{"login":"sloria","id":2379650,"avatar_url":"https://avatars2.githubusercontent.com/u/2379650?v=4","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"created_at":"2018-03-18T18:03:28Z","updated_at":"2018-03-18T18:03:28Z","author_association":"OWNER","body":"I agree with @lafrech 's analysis [above](https://github.com/marshmallow-code/marshmallow/issues/319#issuecomment-356236477). Thanks for the PR. Let's make it so."}}
{"actor":{"display_login":"sloria"}}