Skip to content

Commit 4de6ab1

Browse files
committed
fix: Use default_batch_size for enhanced_search_issues (#2366)
It asked always in batches of 100 items ignoring the configured default_batch_size. This caused timeouts with 500 status on some searches.
1 parent 4dfccbe commit 4de6ab1

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

jira/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def _fetch_pages_searchToken(
918918
item_type: type[ResourceType],
919919
items_key: str | None,
920920
request_path: str,
921-
maxResults: int = 50,
921+
maxResults: int | Literal[False] = 50,
922922
params: dict[str, Any] | None = None,
923923
base: str = JIRA_BASE_URL,
924924
use_post: bool = False,
@@ -929,19 +929,18 @@ def _fetch_pages_searchToken(
929929
item_type (Type[Resource]): Type of single item. Returns a `ResultList` of such items.
930930
items_key (Optional[str]): Path to the items in JSON returned from the server.
931931
request_path (str): Path in the request URL.
932-
maxResults (int): Maximum number of items to return per page. (Default: 50)
932+
maxResults (int): Maximum number of items to return. If maxResults evaluates as False, it will try to get all items in batches. (Default:50)
933933
params (Dict[str, Any]): Parameters to be sent with the request.
934934
base (str): Base URL for the requests.
935935
use_post (bool): Whether to use POST instead of GET.
936936
937937
Returns:
938938
ResultList: List of fetched items.
939939
"""
940-
DEFAULT_BATCH = 100 # Max batch size per request
941940
fetch_all = maxResults in (0, False) # If False/0, fetch everything
942941

943942
page_params = (params or {}).copy() # Ensure params isn't modified
944-
page_params["maxResults"] = DEFAULT_BATCH if fetch_all else maxResults
943+
page_params["maxResults"] = self._get_batch_size(item_type) if fetch_all else maxResults
945944

946945
# Use caller-provided nextPageToken if present
947946
nextPageToken: str | None = page_params.get("nextPageToken")
@@ -2177,7 +2176,7 @@ def createmeta_fieldtypes(
21772176
projectIdOrKey: str | int,
21782177
issueTypeId: str | int,
21792178
startAt: int = 0,
2180-
maxResults: int = 50,
2179+
maxResults: int | Literal[False] = 50,
21812180
) -> dict[str, Any]:
21822181
"""Get the field metadata for a given project and issue type, required to create issues.
21832182
@@ -3091,7 +3090,7 @@ def project_issue_types(
30913090
self,
30923091
project: str,
30933092
startAt: int = 0,
3094-
maxResults: int = 50,
3093+
maxResults: int | Literal[False] = 50,
30953094
) -> ResultList[IssueType]:
30963095
"""Get a list of issue type Resources available in a given project from the server.
30973096
@@ -3121,7 +3120,7 @@ def project_issue_fields(
31213120
project: str,
31223121
issue_type: str,
31233122
startAt: int = 0,
3124-
maxResults: int = 50,
3123+
maxResults: int | Literal[False] = 50,
31253124
) -> ResultList[Field]:
31263125
"""Get a list of field type Resources available for a project and issue type from the server.
31273126
@@ -3557,7 +3556,7 @@ def search_issues(
35573556
self,
35583557
jql_str: str,
35593558
startAt: int = 0,
3560-
maxResults: int = 50,
3559+
maxResults: int | Literal[False] = 50,
35613560
validate_query: bool = True,
35623561
fields: str | list[str] | None = "*all",
35633562
expand: str | None = None,
@@ -3572,7 +3571,7 @@ def search_issues(
35723571
self,
35733572
jql_str: str,
35743573
startAt: int = 0,
3575-
maxResults: int = 50,
3574+
maxResults: int | Literal[False] = 50,
35763575
validate_query: bool = True,
35773576
fields: str | list[str] | None = "*all",
35783577
expand: str | None = None,
@@ -3586,7 +3585,7 @@ def search_issues(
35863585
self,
35873586
jql_str: str,
35883587
startAt: int = 0,
3589-
maxResults: int = 50,
3588+
maxResults: int | Literal[False] = 50,
35903589
validate_query: bool = True,
35913590
fields: str | list[str] | None = "*all",
35923591
expand: str | None = None,
@@ -3693,7 +3692,7 @@ def enhanced_search_issues(
36933692
self,
36943693
jql_str: str,
36953694
nextPageToken: str | None = None,
3696-
maxResults: int = 50,
3695+
maxResults: int | Literal[False] = 50,
36973696
fields: str | list[str] | None = "*all",
36983697
expand: str | None = None,
36993698
reconcileIssues: list[int] | None = None,

0 commit comments

Comments
 (0)