无法通过 python-jira 访问 jira 工作日志

Ale*_*lex 5 python jira

我正在尝试使用jira python 库访问 python 中的工作日志。我正在做以下事情:

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

issue = jira.search_issues("MYTICKET-1")
print(issue.fields.worklogs)
Run Code Online (Sandbox Code Playgroud)

如文档中所述,第 2.1.4 章。但是,我收到以下错误(对于这两种情况):

AttributeError: type object 'PropertyHolder' has no attribute 'worklogs'
Run Code Online (Sandbox Code Playgroud)

有什么我做错了吗?文档是否过时?如何访问工作日志(或其他字段,如评论等)?什么是PropertyHolder?如何访问它(文档中没有描述!)?

Wlo*_*oHu 8

这是因为它似乎 jira.JIRA.search_issues默认情况下不会获取所有“内置”字段,例如worklog(尽管文档仅使用模糊术语“字段 - [...]默认是包含所有字段” - “全部”来自什么?) 。

你要么必须使用jira.JIRA.issue:

client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")
Run Code Online (Sandbox Code Playgroud)

或明确列出您想要获取的字段jira.JIRA.search_issues:

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

另请注意,通过这种方式,您将获得最多 20 个附加到 JIRA 问题实例的工作日志项。如果您需要所有这些,您应该使用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
Run Code Online (Sandbox Code Playgroud)


gin*_*ard 0

这里的这个问题与您的问题类似,有人已经发布了解决方法。

Github 上也有一个与附件(而不是工作日志)相关的类似问题。评论中的最后一个答案有可能有所帮助的解决方法。