{"action":"created","issue":{"url":"https://api.github.com/repos/scitran/core/issues/524","repository_url":"https://api.github.com/repos/scitran/core","labels_url":"https://api.github.com/repos/scitran/core/issues/524/labels{/name}","comments_url":"https://api.github.com/repos/scitran/core/issues/524/comments","events_url":"https://api.github.com/repos/scitran/core/issues/524/events","html_url":"https://github.com/scitran/core/issues/524","id":180971705,"number":524,"title":"Files array on subject input broken","user":{"login":"coltonlw","id":20908947,"avatar_url":"https://avatars.githubusercontent.com/u/20908947?v=3","gravatar_id":"","url":"https://api.github.com/users/coltonlw","html_url":"https://github.com/coltonlw","followers_url":"https://api.github.com/users/coltonlw/followers","following_url":"https://api.github.com/users/coltonlw/following{/other_user}","gists_url":"https://api.github.com/users/coltonlw/gists{/gist_id}","starred_url":"https://api.github.com/users/coltonlw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coltonlw/subscriptions","organizations_url":"https://api.github.com/users/coltonlw/orgs","repos_url":"https://api.github.com/users/coltonlw/repos","events_url":"https://api.github.com/users/coltonlw/events{/privacy}","received_events_url":"https://api.github.com/users/coltonlw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"ryansanford","id":15736230,"avatar_url":"https://avatars.githubusercontent.com/u/15736230?v=3","gravatar_id":"","url":"https://api.github.com/users/ryansanford","html_url":"https://github.com/ryansanford","followers_url":"https://api.github.com/users/ryansanford/followers","following_url":"https://api.github.com/users/ryansanford/following{/other_user}","gists_url":"https://api.github.com/users/ryansanford/gists{/gist_id}","starred_url":"https://api.github.com/users/ryansanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryansanford/subscriptions","organizations_url":"https://api.github.com/users/ryansanford/orgs","repos_url":"https://api.github.com/users/ryansanford/repos","events_url":"https://api.github.com/users/ryansanford/events{/privacy}","received_events_url":"https://api.github.com/users/ryansanford/received_events","type":"User","site_admin":false},"assignees":[{"login":"ryansanford","id":15736230,"avatar_url":"https://avatars.githubusercontent.com/u/15736230?v=3","gravatar_id":"","url":"https://api.github.com/users/ryansanford","html_url":"https://github.com/ryansanford","followers_url":"https://api.github.com/users/ryansanford/followers","following_url":"https://api.github.com/users/ryansanford/following{/other_user}","gists_url":"https://api.github.com/users/ryansanford/gists{/gist_id}","starred_url":"https://api.github.com/users/ryansanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryansanford/subscriptions","organizations_url":"https://api.github.com/users/ryansanford/orgs","repos_url":"https://api.github.com/users/ryansanford/repos","events_url":"https://api.github.com/users/ryansanford/events{/privacy}","received_events_url":"https://api.github.com/users/ryansanford/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2016-10-04T18:40:43Z","updated_at":"2016-10-04T19:17:30Z","closed_at":null,"body":"When creating a new session one of the properties of the session is \"subject\".  One of the properties of subject is the \"files\" array.  Specifying a value for the files array causes a 500 error because there is no code that adds the \"created\" and \"modified\" properties to each document in the files array, which are required by the mongo schema for files, so validation fails when saving to the database\r\n\r\nSession document used as POST body:\r\n\r\n```json\r\n  {\r\n    \"subject\": {\r\n      \"code\": \"test-subject-1\",\r\n      \"files\":[\r\n      \t{\"name\":\"test-file\"}\r\n      ]\r\n    },\r\n    \"label\": \"test-session-1\",\r\n    \"project\": \"57f3f59afc12650027c58a0f\",\r\n    \"public\": false\r\n  }\r\n```\r\n\r\nLog: \r\n\r\n```\r\n→ Create test-session-1\r\n  POST http://localhost:8081/api/sessions?root=true  2016-10-04 18:31:54      scitran.api                  base.py   100:INFO Initialized request request_id=85350149-1475605914\r\n2016-10-04 18:31:54      scitran.api                  base.py   298:DEBU from None admin@user.com POST /api/sessions {u'root': u'true'} request_id=85350149-1475605914\r\n2016-10-04 18:31:54      scitran.api      containerhandler.py   312:DEBU {u'project': u'57f3f59afc12650027c58a0f', u'label': u'test-session-1', u'public': False, u'subject': {u'files': [{u'name': u'test-file'}], u'code': u'test-subject-1'}}\r\n2016-10-04 18:31:54      scitran.api            validators.py    61:DEBU {'group': u'test-group', 'created': datetime.datetime(2016, 10, 4, 18, 31, 54, 427491), 'modified': datetime.datetime(2016, 10, 4, 18, 31, 54, 427491), u'label': u'test-session-1', u'project': ObjectId('57f3f59afc12650027c58a0f'), u'subject': {u'files': [{u'name': u'test-file'}], u'code': u'test-subject-1', '_id': ObjectId('57f3f59afc12650027c58a10')}, u'public': False, 'permissions': [{u'access': u'admin', u'_id': u'admin@user.com', u'site': u'local'}]}\r\n2016-10-04 18:31:54      scitran.api                  base.py   288:ERRO Traceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 570, in dispatch\r\n    return method(*args, **kwargs)\r\n  File \"./api/handlers/containerhandler.py\", line 340, in post\r\n    result = mongo_validator(permchecker(self.storage.exec_op))('POST', payload=payload)\r\n  File \"./api/validators.py\", line 71, in validator\r\n    raise DBValidationException(str(e))\r\nDBValidationException: u'created' is a required property\r\n\r\nFailed validating u'required' in schema[u'properties'][u'subject'][u'properties'][u'files'][u'items']:\r\n    {u'$schema': u'http://json-schema.org/draft-04/schema#',\r\n     u'additionalProperties': False,\r\n     u'key_fields': [u'name'],\r\n     u'properties': {u'created': {},\r\n                     u'hash': {u'type': u'string'},\r\n                     u'instrument': {u'type': u'string'},\r\n                     u'measurements': {u'items': {u'type': u'string'},\r\n                                       u'type': u'array',\r\n                                       u'uniqueItems': True},\r\n                     u'metadata': {u'type': u'object'},\r\n                     u'mimetype': {u'type': u'string'},\r\n                     u'modified': {},\r\n                     u'name': {u'type': u'string'},\r\n                     u'size': {u'type': u'integer'},\r\n                     u'tags': {u'items': {u'type': u'string'},\r\n                               u'type': u'array',\r\n                               u'uniqueItems': True},\r\n                     u'type': {u'type': u'string'}},\r\n     u'required': [u'name', u'created', u'modified', u'size', u'hash'],\r\n     u'type': u'object'}\r\n\r\nOn instance[u'subject'][u'files'][0]:\r\n    {u'name': u'test-file'}\r\n request_id=85350149-1475605914\r\n[500 Internal Server Error, 1.42KB, 47ms]\r\n127.0.0.1 - - [04/Oct/2016:18:31:54 +0000] \"POST /api/sessions?root=true HTTP/1.1\" 500 1459 \"-\" \"PostmanRuntime/2.4.4\" request_id=85350149-1475605914\r\n  1⠄ Status code is 200\r\n  ✓  Response time is less than 200ms\r\n```"},"comment":{"url":"https://api.github.com/repos/scitran/core/issues/comments/251485403","html_url":"https://github.com/scitran/core/issues/524#issuecomment-251485403","issue_url":"https://api.github.com/repos/scitran/core/issues/524","id":251485403,"user":{"login":"nagem","id":5702596,"avatar_url":"https://avatars.githubusercontent.com/u/5702596?v=3","gravatar_id":"","url":"https://api.github.com/users/nagem","html_url":"https://github.com/nagem","followers_url":"https://api.github.com/users/nagem/followers","following_url":"https://api.github.com/users/nagem/following{/other_user}","gists_url":"https://api.github.com/users/nagem/gists{/gist_id}","starred_url":"https://api.github.com/users/nagem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagem/subscriptions","organizations_url":"https://api.github.com/users/nagem/orgs","repos_url":"https://api.github.com/users/nagem/repos","events_url":"https://api.github.com/users/nagem/events{/privacy}","received_events_url":"https://api.github.com/users/nagem/received_events","type":"User","site_admin":false},"created_at":"2016-10-04T19:17:30Z","updated_at":"2016-10-04T19:17:30Z","body":"I'm not sure why it was added, but adding subject files is only supported via the `api/upload` endpoint. "}}
{"actor":{"display_login":"nagem"}}