Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion backend/onyx/connectors/jira/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ def _perform_jql_search(
f"Fetching Jira issues with JQL: {jql}, "
f"starting at {start}, max results: {max_results}"
)
issues = jira_client.search_issues(

# Use custom search method to handle Atlassian's API breaking change
# The old /rest/api/{version}/search endpoint has been deprecated
# New endpoint is /rest/api/{version}/search/jql
issues = _custom_search_issues(
jira_client,
jql_str=jql,
startAt=start,
maxResults=max_results,
Expand All @@ -98,6 +103,67 @@ def _perform_jql_search(
raise RuntimeError(f"Found Jira object not of type Issue: {issue}")


def _custom_search_issues(
jira_client: JIRA,
jql_str: str,
startAt: int = 0,
maxResults: int = 50,
fields: str | None = None,
) -> Iterable[Issue]:
"""
Simple fix for Atlassian's API breaking change.

The old /rest/api/{version}/search endpoint has been deprecated and removed.
New endpoint is /rest/api/{version}/search/jql

This is a minimal fix to resolve the immediate issue. For performance improvements,
see the upgrade instructions in JIRA_API_FIX_SUMMARY.md
"""
if isinstance(fields, str):
fields = fields.split(",")
elif fields is None:
fields = ["*all"]

# Build search parameters - keep the same interface for backwards compatibility
search_params = {
"jql": jql_str,
"startAt": startAt,
"maxResults": maxResults,
"fields": fields,
"validateQuery": True,
}

# Use the new JQL endpoint
url = f"{jira_client.server_url}/rest/api/{jira_client._options.get('rest_api_version', '3')}/search/jql"

# Make the request directly to the new endpoint
response = jira_client._session.post(url, json=search_params)

if response.status_code == 410:
# Fallback to old method if needed (though it should fail now)
logger.warning("JQL endpoint returned 410, falling back to old search method")
return jira_client.search_issues(
jql_str=jql_str,
startAt=startAt,
maxResults=maxResults,
fields=fields,
)
Comment on lines +142 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The fallback to the old search method may not work since the old endpoint is deprecated. Consider logging this as an error and failing fast instead of attempting the deprecated call.


response.raise_for_status()
data = response.json()

# Convert the response to Issue objects
issues = []
for issue_data in data.get("issues", []):
issue = Issue(jira_client, issue_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect Issue instantiation; pass options/session and raw so fields are populated correctly.

Prompt for AI agents
Address the following comment on backend/onyx/connectors/jira/connector.py at line 158:

<comment>Incorrect Issue instantiation; pass options/session and raw so fields are populated correctly.</comment>

<file context>
@@ -98,6 +103,67 @@ def _perform_jql_search(
+    # Convert the response to Issue objects
+    issues = []
+    for issue_data in data.get(&quot;issues&quot;, []):
+        issue = Issue(jira_client, issue_data)
+        # Ensure the issue has the necessary attributes
+        if not hasattr(issue, &quot;key&quot;) and &quot;key&quot; in issue_data:
</file context>
Suggested change
issue = Issue(jira_client, issue_data)
issue = Issue(jira_client._options, jira_client._session, raw=issue_data)

# Ensure the issue has the necessary attributes
if not hasattr(issue, "key") and "key" in issue_data:
issue.key = issue_data["key"]
issues.append(issue)

return issues


def process_jira_issue(
jira_client: JIRA,
issue: Issue,
Expand Down
Loading