{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments/30579745","id":30579745,"diff_hunk":"@@ -135,33 +134,21 @@ def update_service(service_id):\n \n     json_payload = get_json_from_request()\n     json_has_required_keys(json_payload,\n-                           [\"update_details\", \"services\"])\n+                           ['services', 'update_details'])\n \n     update_json = json_payload['update_details']\n     validate_updater_json_or_400(update_json)\n-    service_update = drop_foreign_fields(\n-        json_payload['services'],\n-        ['supplierName', 'links', 'frameworkName', 'status']\n-    )\n-    json_has_matching_id(service_update, service_id)\n \n-    data = dict(service.data.items())\n-    data.update(service_update)\n-    if \"id\" in data:\n-        # It is an old-style service JSON with an id field\n-        data[\"id\"] = str(data[\"id\"])\n-    else:\n-        # It is a new service JSON with id removed from payload already\n-        data[\"id\"] = service_id\n+    json_has_matching_id(json_payload['services'], service_id)\n \n-    detect_framework_or_400(data)\n+    service.update_from_json(json_payload['services'],\n+                             updated_by=update_json['updated_by'],\n+                             updated_reason=update_json['update_reason'])\n \n-    data = drop_foreign_fields(data, ['id'])\n-    now = datetime.now()\n-    service.data = data\n-    service.updated_at = now\n-    service.updated_by = update_json['updated_by']\n-    service.updated_reason = update_json['update_reason']\n+    data = service.serialize()\n+    data = drop_foreign_fields(data,\n+                               ['supplierName', 'links', 'frameworkName'])","path":"app/main/views/services.py","position":46,"original_position":46,"commit_id":"8e1783c573e6a4a89b98178822283d7d0db106db","original_commit_id":"8e1783c573e6a4a89b98178822283d7d0db106db","user":{"login":"TheDoubleK","id":6525554,"avatar_url":"https://avatars.githubusercontent.com/u/6525554?v=3","gravatar_id":"","url":"https://api.github.com/users/TheDoubleK","html_url":"https://github.com/TheDoubleK","followers_url":"https://api.github.com/users/TheDoubleK/followers","following_url":"https://api.github.com/users/TheDoubleK/following{/other_user}","gists_url":"https://api.github.com/users/TheDoubleK/gists{/gist_id}","starred_url":"https://api.github.com/users/TheDoubleK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheDoubleK/subscriptions","organizations_url":"https://api.github.com/users/TheDoubleK/orgs","repos_url":"https://api.github.com/users/TheDoubleK/repos","events_url":"https://api.github.com/users/TheDoubleK/events{/privacy}","received_events_url":"https://api.github.com/users/TheDoubleK/received_events","type":"User","site_admin":false},"body":"But that's only in the import method, not on update?  Are we just trusting that if it was removed when first imported then it shouldn't be there in updates?","created_at":"2015-05-19T08:47:32Z","updated_at":"2015-05-19T08:47:32Z","html_url":"https://github.com/alphagov/digitalmarketplace-api/pull/127#discussion_r30579745","pull_request_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127","_links":{"self":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments/30579745"},"html":{"href":"https://github.com/alphagov/digitalmarketplace-api/pull/127#discussion_r30579745"},"pull_request":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127","id":35651182,"html_url":"https://github.com/alphagov/digitalmarketplace-api/pull/127","diff_url":"https://github.com/alphagov/digitalmarketplace-api/pull/127.diff","patch_url":"https://github.com/alphagov/digitalmarketplace-api/pull/127.patch","issue_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/127","number":127,"state":"open","locked":false,"title":"[#94850520] Fix bug updating g5 services","user":{"login":"robyoung","id":14287,"avatar_url":"https://avatars.githubusercontent.com/u/14287?v=3","gravatar_id":"","url":"https://api.github.com/users/robyoung","html_url":"https://github.com/robyoung","followers_url":"https://api.github.com/users/robyoung/followers","following_url":"https://api.github.com/users/robyoung/following{/other_user}","gists_url":"https://api.github.com/users/robyoung/gists{/gist_id}","starred_url":"https://api.github.com/users/robyoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robyoung/subscriptions","organizations_url":"https://api.github.com/users/robyoung/orgs","repos_url":"https://api.github.com/users/robyoung/repos","events_url":"https://api.github.com/users/robyoung/events{/privacy}","received_events_url":"https://api.github.com/users/robyoung/received_events","type":"User","site_admin":false},"body":"https://www.pivotaltracker.com/story/show/94850520\r\n\r\n## Change update_service to validate whole service\r\nThe change validates the entire serialized service object (minus a small number of foreign fields) against the JSON schema rather than just what is stored in the `data` field. This makes the JSON schema a better reflection of what the HTTP API accepts and produces.\r\n\r\n## Make import_service more like update_service\r\nMove code around so that it flows more similarly to update_service.\r\n\r\nDissallow updates via PUT. All our updates currently go through POST and the import_service method already makes assumptions about it always creating new services (it always returns a 201 status code and always updates the created_at field).\r\n\r\nRemove some redundant tests that are either in the wrong place (testing post in the put test) or no longer necesarry (testing the search API is called on update through the PUT endpoint).\r\n\r\nEnsure supplierId does not make it into the data field, it is in the supplier_id field of the model.","created_at":"2015-05-18T16:37:32Z","updated_at":"2015-05-19T08:47:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19135a30d759b99ad9821d05367f98179a07a9da","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127/commits","review_comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127/comments","review_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/127/comments","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/8e1783c573e6a4a89b98178822283d7d0db106db","head":{"label":"alphagov:fix-bug-updating-g5-services","ref":"fix-bug-updating-g5-services","sha":"8e1783c573e6a4a89b98178822283d7d0db106db","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":26963583,"name":"digitalmarketplace-api","full_name":"alphagov/digitalmarketplace-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/digitalmarketplace-api","description":"Digital Marketplace API.","fork":false,"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api","forks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/forks","keys_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/teams","hooks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/events","assignees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/tags","blobs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscription","commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/merges","archive_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/downloads","issues_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/releases{/id}","created_at":"2014-11-21T14:41:36Z","updated_at":"2015-05-09T02:28:36Z","pushed_at":"2015-05-18T16:37:33Z","git_url":"git://github.com/alphagov/digitalmarketplace-api.git","ssh_url":"git@github.com:alphagov/digitalmarketplace-api.git","clone_url":"https://github.com/alphagov/digitalmarketplace-api.git","svn_url":"https://github.com/alphagov/digitalmarketplace-api","homepage":null,"size":3464,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":4,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"40e3a7e58e234ff996b9d8865f8ba6252b48f275","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":26963583,"name":"digitalmarketplace-api","full_name":"alphagov/digitalmarketplace-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/digitalmarketplace-api","description":"Digital Marketplace API.","fork":false,"url":"https://api.github.com/repos/alphagov/digitalmarketplace-api","forks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/forks","keys_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/teams","hooks_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/events","assignees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/tags","blobs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/subscription","commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/merges","archive_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/downloads","issues_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/digitalmarketplace-api/releases{/id}","created_at":"2014-11-21T14:41:36Z","updated_at":"2015-05-09T02:28:36Z","pushed_at":"2015-05-18T16:37:33Z","git_url":"git://github.com/alphagov/digitalmarketplace-api.git","ssh_url":"git@github.com:alphagov/digitalmarketplace-api.git","clone_url":"https://github.com/alphagov/digitalmarketplace-api.git","svn_url":"https://github.com/alphagov/digitalmarketplace-api","homepage":null,"size":3464,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127"},"html":{"href":"https://github.com/alphagov/digitalmarketplace-api/pull/127"},"issue":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/127"},"comments":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/issues/127/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/pulls/127/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/digitalmarketplace-api/statuses/8e1783c573e6a4a89b98178822283d7d0db106db"}}}}