{"action":"created","issue":{"url":"https://api.github.com/repos/inveniosoftware/invenio-records/issues/21","labels_url":"https://api.github.com/repos/inveniosoftware/invenio-records/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/inveniosoftware/invenio-records/issues/21/comments","events_url":"https://api.github.com/repos/inveniosoftware/invenio-records/issues/21/events","html_url":"https://github.com/inveniosoftware/invenio-records/issues/21","id":102400459,"number":21,"title":"api: patch record not behaving as expected","user":{"login":"eamonnmag","id":282396,"avatar_url":"https://avatars.githubusercontent.com/u/282396?v=3","gravatar_id":"","url":"https://api.github.com/users/eamonnmag","html_url":"https://github.com/eamonnmag","followers_url":"https://api.github.com/users/eamonnmag/followers","following_url":"https://api.github.com/users/eamonnmag/following{/other_user}","gists_url":"https://api.github.com/users/eamonnmag/gists{/gist_id}","starred_url":"https://api.github.com/users/eamonnmag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eamonnmag/subscriptions","organizations_url":"https://api.github.com/users/eamonnmag/orgs","repos_url":"https://api.github.com/users/eamonnmag/repos","events_url":"https://api.github.com/users/eamonnmag/events{/privacy}","received_events_url":"https://api.github.com/users/eamonnmag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-21T15:09:22Z","updated_at":"2015-08-21T19:59:33Z","closed_at":null,"body":"Record.patch currently returns a patched data object, but has no impact on the database record. This is misleading as far as an API call goes. \r\n\r\nI would propose this (open of course to suggestions for improvements) \r\n\r\n``` python\r\ndef patch(self, patch):\r\n        model = self.model\r\n        data = apply_patch(dict(self), patch)\r\n        # perform the commit on the patched data.\r\n\r\n        try:\r\n            patched_record = self.__class__(data, model=model)\r\n            patched_record.commit()\r\n            return patched_record\r\n        except Exception:\r\n            raise\r\n```\r\n\r\nIt would also be good to perhaps return back an updated version of the Record object rather than a new instance."},"comment":{"url":"https://api.github.com/repos/inveniosoftware/invenio-records/issues/comments/133545735","html_url":"https://github.com/inveniosoftware/invenio-records/issues/21#issuecomment-133545735","issue_url":"https://api.github.com/repos/inveniosoftware/invenio-records/issues/21","id":133545735,"user":{"login":"dset0x","id":8993055,"avatar_url":"https://avatars.githubusercontent.com/u/8993055?v=3","gravatar_id":"","url":"https://api.github.com/users/dset0x","html_url":"https://github.com/dset0x","followers_url":"https://api.github.com/users/dset0x/followers","following_url":"https://api.github.com/users/dset0x/following{/other_user}","gists_url":"https://api.github.com/users/dset0x/gists{/gist_id}","starred_url":"https://api.github.com/users/dset0x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dset0x/subscriptions","organizations_url":"https://api.github.com/users/dset0x/orgs","repos_url":"https://api.github.com/users/dset0x/repos","events_url":"https://api.github.com/users/dset0x/events{/privacy}","received_events_url":"https://api.github.com/users/dset0x/received_events","type":"User","site_admin":false},"created_at":"2015-08-21T19:59:33Z","updated_at":"2015-08-21T19:59:33Z","body":"It's worth noting that `jsonpatch.apply_patch(src, dst, in_place=True)` will not touch any attributes of the record, so splitting the `model` from the `data` seems superfluous.\r\n\r\n> It would also be good to perhaps return back an updated version of the Record object rather than a new instance.\r\n\r\nIdeally, yes, the user would have the same object reference. This may be a bit tricky to get right however, since we'd have to not instantiate a new SQLAlchemy, potentially skipping some initialization code.\r\n\r\n---\r\n\r\nSpeaking of this function, is it within the scope of `invenio-records` to optionally also safeguard against patches that are directed to older versions of the record (ie provide some kind of atomic operation so that we know we're modifying the record version that we intend to)."}}