Cannot access key attribute from JIRA search results using python-jira library

I’m building a JIRA automation script with the python-jira package and running into an issue when trying to get the issue key from search results.

def get_issue_by_summary(query_text):
    global jira_client
    issues = jira_client.search_issues('project=DEV and status != Closed and summary ~ "API GATEWAY-SVC:HANDLER1-ENDPOINT" order by created', maxResults=1)
    return issues

This function works fine and returns a jira object like this:

[<JIRA Issue: key=u'DEV-25', id=u'220845'>]

But when I try to access the key property directly:

issues.key

I’m getting this error message:

AttributeError: 'ResultList' object has no attribute 'key'

How can I properly extract the issue key from the search results? What’s the correct way to access individual issue properties from the returned object?

you gotta remember, search_issues returns a list of results, not a single issue. just use issues[0].key to get the key from the first item. always returns a ResultList, even if there’s just one thing.

Had this exact same issue when I started using python-jira. The library always wraps results in a ResultList container, even with maxResults=1. You’d think it would return a single issue object, but nope - you still need to grab the first element with issues[0].key. I’d throw in a quick if len(issues) > 0: check before accessing the key, especially if your search might come up empty sometimes. Saved me from crashes in production more than once.

The search_issues method always returns a ResultList that behaves like a list, even if you set maxResults=1. You can’t access issue attributes directly on it; you’ll need to iterate through or use an index. To get the key for your expected result, you can use issues[0].key. However, make sure to check if the list isn’t empty first to avoid an IndexError when no issues match. A safer approach would be if issues: return issues[0].key. Remember, the ResultList doesn’t have issue attributes, but the individual Issue objects inside do.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.