From 74f6490d05a6340cc2b79f7aa4448ff4098bc224 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Sat, 25 May 2024 14:43:18 -0400 Subject: [PATCH 1/5] adding warning when requests_futures isnt installed --- jira/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jira/client.py b/jira/client.py index ff311bcd6..e7cd07bfd 100644 --- a/jira/client.py +++ b/jira/client.py @@ -798,6 +798,11 @@ def _fetch_pages( async_class = FuturesSession except ImportError: + msg = ( + "async option requires requests-futures to be installed. " + "falling back to synchronous implementation." + ) + warnings.warn(msg) pass async_workers = self._options.get("async_workers") From e19640d483b179c10a951375bb020a3b4c164aac Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Sun, 30 Jun 2024 20:49:07 -0400 Subject: [PATCH 2/5] updated afters dimitarOnGithub input --- jira/client.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/jira/client.py b/jira/client.py index e7cd07bfd..84243713f 100644 --- a/jira/client.py +++ b/jira/client.py @@ -573,7 +573,22 @@ def __init__( if server: options["server"] = server + + options["async_class"] = None if async_: + if self._options["async"]: + try: + from requests_futures.sessions import FuturesSession + + options["async_class"] = FuturesSession + except ImportError: + msg = ( + "async option requires requests-futures to be installed. " + "falling back to synchronous implementation." + ) + warnings.warn(msg) + pass + options["async"] = async_ options["async_workers"] = async_workers @@ -790,21 +805,6 @@ def _fetch_pages( Returns: ResultList """ - async_workers = None - async_class = None - if self._options["async"]: - try: - from requests_futures.sessions import FuturesSession - - async_class = FuturesSession - except ImportError: - msg = ( - "async option requires requests-futures to be installed. " - "falling back to synchronous implementation." - ) - warnings.warn(msg) - pass - async_workers = self._options.get("async_workers") def json_params() -> dict[str, Any]: # passing through json.dumps and json.loads ensures json @@ -852,6 +852,7 @@ def json_params() -> dict[str, Any]: page_size, ) page_start = (startAt or start_at_from_response or 0) + page_size + async_class = self._options["async_class"] if ( async_class is not None and not is_last @@ -859,7 +860,8 @@ def json_params() -> dict[str, Any]: ): async_fetches = [] future_session = async_class( - session=self._session, max_workers=async_workers + session=self._session, + max_workers=self._options["async_workers"], ) for start_index in range(page_start, total, page_size): page_params = json_params() From 4fe96c97c63e412d993b0ed6c8c442a47a5adc58 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Wed, 10 Jul 2024 08:58:00 -0400 Subject: [PATCH 3/5] updated with adehad suggestions --- jira/client.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jira/client.py b/jira/client.py index 84243713f..cb6cf2db3 100644 --- a/jira/client.py +++ b/jira/client.py @@ -103,6 +103,12 @@ except ImportError: pass +try: + from requests_futures.sessions import FuturesSession +except ImportError: + FuturesSession = None + pass + LOG = _logging.getLogger("jira") LOG.addHandler(_logging.NullHandler()) @@ -574,20 +580,15 @@ def __init__( if server: options["server"] = server - options["async_class"] = None if async_: if self._options["async"]: - try: - from requests_futures.sessions import FuturesSession - - options["async_class"] = FuturesSession - except ImportError: + if FuturesSession is None: msg = ( "async option requires requests-futures to be installed. " - "falling back to synchronous implementation." + "falling back to synchronous implementation.\n" + "to enable async, install the 'async' extra, e.g. pip install jira[async]" ) warnings.warn(msg) - pass options["async"] = async_ options["async_workers"] = async_workers @@ -852,14 +853,13 @@ def json_params() -> dict[str, Any]: page_size, ) page_start = (startAt or start_at_from_response or 0) + page_size - async_class = self._options["async_class"] if ( - async_class is not None + FuturesSession is not None and not is_last and (total is not None and len(items) < total) ): async_fetches = [] - future_session = async_class( + future_session = FuturesSession( session=self._session, max_workers=self._options["async_workers"], ) @@ -883,7 +883,7 @@ def json_params() -> dict[str, Any]: ) items.extend(next_items_page) while ( - async_class is None + FuturesSession is None and not is_last and (total is None or page_start < total) and len(next_items_page) == page_size From 797ec7cde46371e30a09436e518ed9dc94446834 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Thu, 11 Jul 2024 00:13:17 -0400 Subject: [PATCH 4/5] fixed bug --- jira/client.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/jira/client.py b/jira/client.py index cb6cf2db3..ffba16c9b 100644 --- a/jira/client.py +++ b/jira/client.py @@ -581,14 +581,13 @@ def __init__( options["server"] = server if async_: - if self._options["async"]: - if FuturesSession is None: - msg = ( - "async option requires requests-futures to be installed. " - "falling back to synchronous implementation.\n" - "to enable async, install the 'async' extra, e.g. pip install jira[async]" - ) - warnings.warn(msg) + if FuturesSession is None: + msg = ( + "async option requires requests-futures to be installed. " + "falling back to synchronous implementation.\n" + "to enable async, install the 'async' extra, e.g. pip install jira[async]" + ) + warnings.warn(msg) options["async"] = async_ options["async_workers"] = async_workers From 34ae65e42a86b350152f1d2acfc73a064455aa12 Mon Sep 17 00:00:00 2001 From: Richie Cahill Date: Thu, 11 Jul 2024 00:28:11 -0400 Subject: [PATCH 5/5] fixed bug --- jira/client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jira/client.py b/jira/client.py index ffba16c9b..1bf10cfcb 100644 --- a/jira/client.py +++ b/jira/client.py @@ -853,7 +853,8 @@ def json_params() -> dict[str, Any]: ) page_start = (startAt or start_at_from_response or 0) + page_size if ( - FuturesSession is not None + self._options["async"] + and FuturesSession is not None and not is_last and (total is not None and len(items) < total) ): @@ -882,7 +883,7 @@ def json_params() -> dict[str, Any]: ) items.extend(next_items_page) while ( - FuturesSession is None + not self._options["async"] and not is_last and (total is None or page_start < total) and len(next_items_page) == page_size