You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python JIRA库enhanced_search_issues无法获取Resolution Information字段

问题:Python JIRA库enhanced_search_issues无法获取Resolution Information字段

使用Python JIRA库的enhanced_search_issues方法查询JIRA问题时,无法获取到Resolution Information字段(即解决描述段落),但能正常获取解决状态(Done、Fixed等)。已遍历issue.fields的所有字段,未找到该字段,且排除了权限问题。

用于排查的代码:

from jira import JIRA
from jira.resources import PropertyHolder

issues = jira.enhanced_search_issues(
    jql="project = 'MY_PROJECT' AND created >= '2023-01-01'",
    maxResults=100,
    expand="comments,attachments"
)

self.logger.info(f"Inspecting fields for issue {issue_key}")
all_fields = dir(issue.fields)
self.logger.info(f"All available fields in issue.fields: {all_fields}")

self.logger.info(f"Printing values of all fields for issue {issue_key}:")

for field in all_fields:
    if not field.startswith("_"):  
        try:
            field_value = getattr(issue.fields, field, None)
            self.logger.info(f"Field: {field}, Value: {field_value}")
        except Exception as e:
            self.logger.warning(f"Could not retrieve value for field {field}: {e}")

解决方案

1. 确认Resolution Information的实际字段键

Resolution Information大概率是自定义字段,JIRA API中自定义字段不会用显示名称作为访问键,而是类似customfield_XXXX的格式。先通过以下代码找到该字段的实际键:

# 获取所有JIRA字段
all_jira_fields = jira.fields()

# 查找显示名称为"Resolution Information"的字段
for field in all_jira_fields:
    if field['name'] == 'Resolution Information':
        print(f"字段键: {field['key']}, 字段ID: {field['id']}")

运行后会得到类似customfield_10015的字段键。

2. 在enhanced_search_issues中显式指定字段

默认情况下enhanced_search_issues不会返回所有字段,需通过fields参数指定要包含的字段,包括找到的自定义字段键:

# 替换成你获取到的Resolution Information字段键
resolution_info_field_key = "customfield_10015"

issues = jira.enhanced_search_issues(
    jql="project = 'MY_PROJECT' AND created >= '2023-01-01'",
    maxResults=100,
    expand="comments,attachments",
    # 指定需要获取的字段,*all表示默认字段,加上自定义字段键
    fields="*all," + resolution_info_field_key
)

# 访问Resolution Information字段
for issue in issues:
    resolution_info = getattr(issue.fields, resolution_info_field_key, None)
    print(f"Issue {issue.key} 的Resolution Information: {resolution_info}")

3. 备选:改用search_issues方法

如果enhanced_search_issues仍有问题,可尝试使用search_issues方法,同样指定fields参数:

issues = jira.search_issues(
    jql="project = 'MY_PROJECT' AND created >= '2023-01-01'",
    maxResults=100,
    expand="comments,attachments",
    fields="*all," + resolution_info_field_key
)

for issue in issues:
    resolution_info = getattr(issue.fields, resolution_info_field_key, None)
    print(f"Issue {issue.key} 的Resolution Information: {resolution_info}")

内容的提问来源于stack exchange,提问作者Peter Walker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 20:33:20