Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to access jira worklogs via python-jira

Tags:

python

jira

I am trying to access the worklogs in python by using the jira python library. I am doing the following:

issues = jira.search_issues("key=MYTICKET-1")
print(issues[0].fields.worklogs)

issue = jira.search_issues("MYTICKET-1")
print(issue.fields.worklogs)

as described in the documentation, chapter 2.1.4. However, I get the following error (for both cases):

AttributeError: type object 'PropertyHolder' has no attribute 'worklogs'

Is there something I am doing wrong? Is the documentation outdated? How to access worklogs (or other fields, like comments etc)? And what is a PropertyHolder? How to access it (its not described in the documentation!)?

like image 405
Alex Avatar asked Oct 18 '22 18:10

Alex


1 Answers

This is because it seems jira.JIRA.search_issues doesn't fetch all "builtin" fields, like worklog, by default (although documentation only uses vague term "fields - [...] Default is to include all fields" - "all" out of what?).

You either have to use jira.JIRA.issue:

client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")

or explicitly list fields which you want to fetch in jira.JIRA.search_issues:

client = jira.JIRA(...)
issue = client.search_issues("key=MYTICKET-1", fields=[..., 'worklog'])[0]

Also be aware that this way you will get at most 20 worklog items attached to your JIRA issue instance. If you need all of them you should use jira.JIRA.worklogs:

client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")
worklog = issue.fields.worklog
all_worklogs = client.worklogs(issue) if worklog.total > 20 else worklog.worklogs
like image 84
WloHu Avatar answered Oct 20 '22 11:10

WloHu