{"action":"created","issue":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3169","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3169/labels{/name}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3169/comments","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3169/events","html_url":"https://github.com/tomchristie/django-rest-framework/pull/3169","id":95658953,"number":3169,"title":"Add error codes to ValidationError","user":{"login":"qsorix","id":224864,"avatar_url":"https://avatars.githubusercontent.com/u/224864?v=3","gravatar_id":"","url":"https://api.github.com/users/qsorix","html_url":"https://github.com/qsorix","followers_url":"https://api.github.com/users/qsorix/followers","following_url":"https://api.github.com/users/qsorix/following{/other_user}","gists_url":"https://api.github.com/users/qsorix/gists{/gist_id}","starred_url":"https://api.github.com/users/qsorix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qsorix/subscriptions","organizations_url":"https://api.github.com/users/qsorix/orgs","repos_url":"https://api.github.com/users/qsorix/repos","events_url":"https://api.github.com/users/qsorix/events{/privacy}","received_events_url":"https://api.github.com/users/qsorix/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/labels/Enhancement","name":"Enhancement","color":"009800"},{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/labels/Needs%20further%20review","name":"Needs further review","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":26,"created_at":"2015-07-17T13:45:26Z","updated_at":"2015-11-24T09:32:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/3169","html_url":"https://github.com/tomchristie/django-rest-framework/pull/3169","diff_url":"https://github.com/tomchristie/django-rest-framework/pull/3169.diff","patch_url":"https://github.com/tomchristie/django-rest-framework/pull/3169.patch"},"body":"This change addresses use cases that require more information about reported\r\nvalidation errors. Currently for each error that REST Framework reports users\r\nget only that error's message string. The message can be translated so there's\r\nno good way to recognize programmatically what sort of an error it is.\r\n\r\nWhen building an API that is supposed to return error codes, I've found it very\r\nlimiting. For example, I was supposed to differentiate between missing fields\r\nand invalid arguments.\r\n\r\nThis commit introduces proper error codes handling to the ValidationError.\r\n\r\nValidationError can hold a single error itself (text), a list of those, or a\r\ndictionary mapping errors to fields. Error code is only meaningful for a single\r\nerror, and I've added assertions to check for proper usage.\r\n\r\nTo help with my development, I've added a setting that makes error code a\r\nmandatory argument. Thanks to this, I was able to correct all uses of\r\nValidationError across the code.\r\n\r\nTo maintain backward compatibility, I'm not passing error codes when building\r\ncompound errors (e.g. a dictionary with all validation errors). However, users\r\n(me) can now monkey patch ValidationError.build_detail method, to store the\r\ncodes."},"comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments/159207406","html_url":"https://github.com/tomchristie/django-rest-framework/pull/3169#issuecomment-159207406","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/3169","id":159207406,"user":{"login":"johnraz","id":304164,"avatar_url":"https://avatars.githubusercontent.com/u/304164?v=3","gravatar_id":"","url":"https://api.github.com/users/johnraz","html_url":"https://github.com/johnraz","followers_url":"https://api.github.com/users/johnraz/followers","following_url":"https://api.github.com/users/johnraz/following{/other_user}","gists_url":"https://api.github.com/users/johnraz/gists{/gist_id}","starred_url":"https://api.github.com/users/johnraz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnraz/subscriptions","organizations_url":"https://api.github.com/users/johnraz/orgs","repos_url":"https://api.github.com/users/johnraz/repos","events_url":"https://api.github.com/users/johnraz/events{/privacy}","received_events_url":"https://api.github.com/users/johnraz/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T09:32:48Z","updated_at":"2015-11-24T09:32:48Z","body":"@qsorix I fully agree. I'm just trying to push this forward. \r\n\r\n@tomchristie : can you give us a hint that we are going in the right direction here, I'm really wanting to make this happen, I just would like to avoid useless work if possible."}}