From 43ed02d95b9699dbcb122ba3553985671e238bfc Mon Sep 17 00:00:00 2001 From: Wojciech Maziarz Date: Mon, 2 Sep 2024 16:56:21 +0200 Subject: [PATCH] use fields_cache --- jira/client.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/jira/client.py b/jira/client.py index 126c73b75..6ca2817eb 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1800,10 +1800,9 @@ def issue( issue = Issue(self._options, self._session) - translation_map: dict[str, str] = {} params = {} if fields is not None: - fields_list, translation_map = self._translate_fields_name_to_id(fields) + fields_list = self._translate_fields_name_to_id(fields) params["fields"] = ",".join(fields_list) if expand is not None: params["expand"] = expand @@ -1811,7 +1810,7 @@ def issue( params["properties"] = properties issue.find(id, params=params) - self._untranslate_issue_fields_id_to_fields_name([issue], translation_map) + self._untranslate_issues_fields_id_to_fields_name([issue]) return issue def create_issue( @@ -3525,7 +3524,7 @@ def search_issues( elif fields is None: fields = ["*all"] - fields, translation_map = self._translate_fields_name_to_id(fields) + fields = self._translate_fields_name_to_id(fields) search_params = { "jql": jql_str, @@ -3561,12 +3560,12 @@ def search_issues( use_post=use_post, ) - self._untranslate_issue_fields_id_to_fields_name(issues, translation_map) + self._untranslate_issues_fields_id_to_fields_name(issues) return issues def _translate_fields_name_to_id( self, fields: list[str] | str - ) -> tuple[list[str], dict[str, str]]: + ) -> list[str]: """Translate fields names to JIRA's REST API field id. Args: @@ -3587,33 +3586,25 @@ def _translate_fields_name_to_id( "Translating fields for <%s> type is unsupported", type(fields) ) - translation_map = {} if self._fields_cache: for i, field_name in enumerate(translated_fields): if field_name in self._fields_cache: - translation_map[self._fields_cache[field_name]] = translated_fields[ - i - ] translated_fields[i] = self._fields_cache[field_name] - return translated_fields, translation_map + return translated_fields - @staticmethod - def _untranslate_issue_fields_id_to_fields_name( - issues: list[Issue], translation_map: dict[str, str] - ) -> None: + def _untranslate_issues_fields_id_to_fields_name(self, issues: list[Issue]) -> None: """Untranslate issues fields names from JIRA's REST API field id. Args: issues (list[Issue]): list of issues to be untranslated - translation_map (dict[str, str]): translation dict containing original field name and field id """ - if not translation_map: + if not self._fields_cache: return for issue in issues: if not issue.raw: return - for field_id, field_name in translation_map.items(): + for field_name, field_id in self._fields_cache.items(): if field_id in issue.raw.get("fields", {}): issue.raw["fields"][field_name] = issue.raw["fields"][field_id] setattr(issue.fields, field_name, issue.raw["fields"][field_id])