Skip to content

Commit 08c5f82

Browse files
committed
Jira: Cant get JQL data with
atlassian-api#1632
1 parent 0eb26b4 commit 08c5f82

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

atlassian/jira/jira_server.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,9 @@ def get_all_fields(self) -> T_resp_json:
982982
Returns a list of all fields, both System and Custom
983983
:return: application/jsonContains a full representation of all visible fields in JSON.
984984
"""
985-
url = self.resource_url("field")
985+
# Jira Cloud's v3 field resource is the current endpoint and includes
986+
# custom fields visible to the caller. Keep Server/Data Center on v2.
987+
url = self.resource_url("field", api_version=3 if self.cloud else None)
986988
return self.get(url)
987989

988990
def create_custom_field(
@@ -4114,7 +4116,10 @@ def enhanced_jql(
41144116
params["jql"] = jql
41154117
if expand is not None:
41164118
params["expand"] = expand
4117-
url = self.resource_url("search/jql")
4119+
# Enhanced JQL is only available at Jira Cloud REST API v3. The
4120+
# legacy-compatible Jira client defaults to v2, so it must not use its
4121+
# configured API version here.
4122+
url = self.resource_url("search/jql", api_version=3)
41184123
return self.get(url, params=params)
41194124

41204125
def approximate_issue_count(
@@ -4272,7 +4277,7 @@ def enhanced_jql_get_list_of_tickets(
42724277
if expand is not None:
42734278
params["expand"] = expand
42744279

4275-
url = self.resource_url("search/jql")
4280+
url = self.resource_url("search/jql", api_version=3)
42764281
results = []
42774282
next_page_token = None
42784283

tests/test_jira.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ def test_get_custom_fields_uses_query_parameter_in_cloud(self, mock_get):
6262
mock_get.call_args.kwargs["params"], {"query": "Customer tier", "startAt": 1, "maxResults": 50}
6363
)
6464

65+
@patch.object(jira.Jira, "get")
66+
def test_get_all_fields_uses_v3_for_cloud(self, mock_get):
67+
self.jira.get_all_fields()
68+
69+
mock_get.assert_called_once_with("rest/api/3/field")
70+
71+
@patch.object(jira.Jira, "get")
72+
def test_enhanced_jql_uses_the_cloud_v3_endpoint(self, mock_get):
73+
self.jira.enhanced_jql(
74+
"created >= -30d ORDER BY created DESC",
75+
fields="summary,description",
76+
nextPageToken="next-token",
77+
expand="names",
78+
)
79+
80+
mock_get.assert_called_once_with(
81+
"rest/api/3/search/jql",
82+
params={
83+
"jql": "created >= -30d ORDER BY created DESC",
84+
"fields": "summary,description",
85+
"nextPageToken": "next-token",
86+
"expand": "names",
87+
},
88+
)
89+
6590
def test_get_epic_issues(self):
6691
resp = self.jira.epic_issues("BAR-22")
6792
self.assertIsInstance(resp["issues"], list)

0 commit comments

Comments
 (0)