From 343f8745bb96ef2c721e16f0c567ad68475b5c57 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:58:57 +0200 Subject: [PATCH] Refactor draft record check --- lib/galaxy/files/sources/invenio.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/galaxy/files/sources/invenio.py b/lib/galaxy/files/sources/invenio.py index ee11124581bd..aa502924478e 100644 --- a/lib/galaxy/files/sources/invenio.py +++ b/lib/galaxy/files/sources/invenio.py @@ -283,16 +283,16 @@ def _get_download_file_url(self, record_id: str, filename: str, user_context: Op return download_file_content_url def _is_draft_record(self, record_id: str, user_context: OptionalUserContext = None): - try: - self._get_draft_record(record_id, user_context) - return True - except Exception as e: - if "404" in str(e): - return False - raise e + request_url = self._get_draft_record_url(record_id) + headers = self._get_request_headers(user_context) + response = requests.get(request_url, headers=headers) + return response.status_code == 200 + + def _get_draft_record_url(self, record_id: str): + return f"{self.records_url}/{record_id}/draft" def _get_draft_record(self, record_id: str, user_context: OptionalUserContext = None): - request_url = f"{self.records_url}/{record_id}/draft" + request_url = self._get_draft_record_url(record_id) draft_record = self._get_response(user_context, request_url) return draft_record