3

I am working on a tool for Jira using the python-jira library.

def find_ticket_key_by_name(search_string):
    global jira
    result = jira.search_issues('project=FSA and status != Done  and summary ~ "HOST TESTER-APP:SERVICE1-SERVICECOUNT" order by createdDate', maxResults=1)
    return result

The function above successfully returns a jira object

[<JIRA Issue: key=u'FSA-11', id=u'119060'>]

however if I attempt to print the key value

result.key

I get this error

AttributeError: 'ResultList' object has no attribute 'key'
Arturski
  • 1,142
  • 3
  • 14
  • 26

3 Answers3

2

I found the problem and posting solution in case somebody gets stuck like me.

In my case I am only returning one result and I assumed it will return one object.

This is not the case as indicated by the "ResultList" error. Even if you return 1 result the function will still return a list with 1 result.

Arturski
  • 1,142
  • 3
  • 14
  • 26
0

What you are getting is a List in python, so try the following:-

  • result[0].key to get the key value
  • result[0].id to get id value.

You can always check type any data using type keyword, in your case it will be class 'jira.client.ResultList' which is a List object

sattva_venu
  • 677
  • 8
  • 22
0

If you want to get the key of issue you searched,

if result:
  for issue in result:
    print(issue.key)

It should help.