{"action":"created","issue":{"url":"https://api.github.com/repos/hyperledger/composer/issues/4241","repository_url":"https://api.github.com/repos/hyperledger/composer","labels_url":"https://api.github.com/repos/hyperledger/composer/issues/4241/labels{/name}","comments_url":"https://api.github.com/repos/hyperledger/composer/issues/4241/comments","events_url":"https://api.github.com/repos/hyperledger/composer/issues/4241/events","html_url":"https://github.com/hyperledger/composer/issues/4241","id":339353679,"node_id":"MDU6SXNzdWUzMzkzNTM2Nzk=","number":4241,"title":"Sever returns status code 500 when using PUT API","user":{"login":"AiDirex","id":3137261,"node_id":"MDQ6VXNlcjMxMzcyNjE=","avatar_url":"https://avatars0.githubusercontent.com/u/3137261?v=4","gravatar_id":"","url":"https://api.github.com/users/AiDirex","html_url":"https://github.com/AiDirex","followers_url":"https://api.github.com/users/AiDirex/followers","following_url":"https://api.github.com/users/AiDirex/following{/other_user}","gists_url":"https://api.github.com/users/AiDirex/gists{/gist_id}","starred_url":"https://api.github.com/users/AiDirex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AiDirex/subscriptions","organizations_url":"https://api.github.com/users/AiDirex/orgs","repos_url":"https://api.github.com/users/AiDirex/repos","events_url":"https://api.github.com/users/AiDirex/events{/privacy}","received_events_url":"https://api.github.com/users/AiDirex/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-09T08:33:54Z","updated_at":"2018-07-11T04:12:08Z","closed_at":null,"author_association":"NONE","body":"## Context\r\nWhen I try to edit an entity using the composer-rest-server PUT API, the server returns status code 500. but when I try to fetch the resource using GET the edited entity is returned. so the server should return 200.\r\n\r\nI have just followed steps from [here](https://hyperledger.github.io/composer/latest/tutorials/developer-tutorial) and [here](https://hyperledger.github.io/composer/latest/tutorials/queries). my models and logics and acl looks same as the examples.\r\n\r\nResponse body:\r\n```\r\n{\r\n  \"error\": {\r\n    \"statusCode\": 500,\r\n    \"name\": \"TypeError\",\r\n    \"message\": \"Cannot read property 'tradeId' of undefined\",\r\n    \"stack\": \"TypeError: Cannot read property 'tradeId' of undefined\\n    at /home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:3106:25\\n    at doNotify (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\\n    at doNotify (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\\n    at doNotify (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\\n    at doNotify (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\\n    at Function.ObserverMixin._notifyBaseObservers (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:178:5)\\n    at Function.ObserverMixin.notifyObserversOf (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\\n    at Function.ObserverMixin._notifyBaseObservers (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)\\n    at Function.ObserverMixin.notifyObserversOf (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\\n    at Function.ObserverMixin._notifyBaseObservers (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)\\n    at Function.ObserverMixin.notifyObserversOf (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\\n    at Function.ObserverMixin._notifyBaseObservers (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)\\n    at Function.ObserverMixin.notifyObserversOf (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\\n    at replaceCallback (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:3103:17)\\n    at ensureConnected.then.then.then (/home/aidin/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/loopback-connector-composer/lib/businessnetworkconnector.js:596:17)\\n    at <anonymous>\"\r\n  }\r\n}\r\n```\r\n## Expected Behavior\r\nThe server should return staus code 200.\r\n## Actual Behavior\r\nThe server returns status code 500 but the entity is edited\r\n## Possible Fix\r\nThe stack trace points to the line 3106 of dao.js file. I looked at it and it seems something for observers (Model.notifyObserversOf('loaded', ctx, ...)). ctx.data is undefined so the server throws an error. Edit operation is sucessfull but the observer fails.\r\n## Steps to Reproduce\r\nI have just followed steps from [here](https://hyperledger.github.io/composer/latest/tutorials/developer-tutorial) and [here](https://hyperledger.github.io/composer/latest/tutorials/queries). my models and logics and acl looks same as the examples.\r\n## Your Environment\r\ncomposer: 0.9.12\r\nnode: 8.11.3\r\nOS: Ubuntu Xenial 64bit"},"comment":{"url":"https://api.github.com/repos/hyperledger/composer/issues/comments/404039277","html_url":"https://github.com/hyperledger/composer/issues/4241#issuecomment-404039277","issue_url":"https://api.github.com/repos/hyperledger/composer/issues/4241","id":404039277,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNDAzOTI3Nw==","user":{"login":"labcoinpoc","id":32951296,"node_id":"MDQ6VXNlcjMyOTUxMjk2","avatar_url":"https://avatars3.githubusercontent.com/u/32951296?v=4","gravatar_id":"","url":"https://api.github.com/users/labcoinpoc","html_url":"https://github.com/labcoinpoc","followers_url":"https://api.github.com/users/labcoinpoc/followers","following_url":"https://api.github.com/users/labcoinpoc/following{/other_user}","gists_url":"https://api.github.com/users/labcoinpoc/gists{/gist_id}","starred_url":"https://api.github.com/users/labcoinpoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/labcoinpoc/subscriptions","organizations_url":"https://api.github.com/users/labcoinpoc/orgs","repos_url":"https://api.github.com/users/labcoinpoc/repos","events_url":"https://api.github.com/users/labcoinpoc/events{/privacy}","received_events_url":"https://api.github.com/users/labcoinpoc/received_events","type":"User","site_admin":false},"created_at":"2018-07-11T04:12:08Z","updated_at":"2018-07-11T04:12:08Z","author_association":"NONE","body":"Same Error\r\n```\r\n\"error\": {\r\n    \"statusCode\": 500,\r\n    \"name\": \"TypeError\",\r\n    \"message\": \"Cannot read property 'userId' of undefined\",\r\n    \"stack\": \"TypeError: Cannot read property 'userId' of undefined\\n    at ........\r\n  }\r\n```"}}
{"actor":{"display_login":"labcoinpoc"}}