Alex
Alex

Reputation: 44325

Unable to access jira worklogs via 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!)?

Upvotes: 6

Views: 4422

Answers (2)

WloHu
WloHu

Reputation: 1527

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

Upvotes: 8

gincard
gincard

Reputation: 1904

This question here is similar to yours and someone has posted a work around.

There is a also a similar question on Github in relation to attachments (not worklogs). The last answer in the comments has workaround that might assist.

Upvotes: 0

Related Questions