diff --git a/invenio_drafts_resources/services/records/service.py b/invenio_drafts_resources/services/records/service.py index 2a1c50e3..69f35709 100644 --- a/invenio_drafts_resources/services/records/service.py +++ b/invenio_drafts_resources/services/records/service.py @@ -196,9 +196,23 @@ def read_draft(self, identity, id_, expand=False): ) def read_latest(self, identity, id_, expand=False): - """Retrieve latest record.""" + """Retrieve latest record. + + If provided with the ID of a parent record it will resolve it and return the latest version of the record. + """ # Resolve and require permission - record = self.record_cls.pid.resolve(id_) + + try: + record = self.record_cls.pid.resolve(id_) + except NoResultFound: + parent_pid = self.record_cls.parent_record_cls.pid.resolve(id_) + version_state = self.record_cls.versions.resolve( + parent_id=parent_pid.pid.object_uuid + ) + if version_state and version_state.latest_id: + record = self.record_cls.get_record(version_state.latest_id) + else: + raise NoResultFound("Failed to fetch the record versions.") # Retrieve latest if record is not if not record.versions.is_latest: diff --git a/tests/resources/test_record_resource.py b/tests/resources/test_record_resource.py index cdd32084..023dcd0b 100644 --- a/tests/resources/test_record_resource.py +++ b/tests/resources/test_record_resource.py @@ -147,7 +147,7 @@ def test_search_versions(client, headers, input_data, location, search_clear): def test_create_publish_new_revision( - client, headers, input_data, location, search_clear + app, db, client, headers, input_data, location, search_clear ): """Test draft creation of an existing record and publish it.""" recid = _create_and_publish(client, headers, input_data)