You need to enable JavaScript to run this app. 使用Python更新JIRA单选按钮字段报Option id 'null'无效错误如何解决
优惠活动
大模型
产品
解决方案
定价
更多

使用Python更新JIRA单选按钮字段报Option id 'null'无效错误如何解决

问题根因
  • 未正确绑定Jira自定义字段ID:报错和HTML结构显示你要操作的单选字段ID为customfield_10543,但你代码中的having_pet变量没有被赋值为该字段ID,导致字段没有被正确写入请求参数,接口识别为null值
  • 传参格式错误:Jira单选字段支持两种传参格式,你把选项ID塞到了value参数中,格式不匹配:
    • 传选项显示文本:{'value': 'Yes/No'}
    • 传HTML中抓取的选项ID:{'id': '10461/10462'}
  • 缺少兜底逻辑:如果df.having_pet.iloc[i]的值不是大写的YES/NO(比如出现小写、空值、其他异常值),对应字段不会被赋值,也会触发null报错
  • 存在语法错误:构建new_issue字典时末尾错误使用了右括号),应该使用大括号}
修复后的实现代码
# 先绑定实际的单选字段ID
having_pet = "customfield_10543"
options = ['10461','10462']
new_issues = []

# 遍历df的逻辑可根据你的实际需求调整
for i in range(len(df)):
    new_issue = {
        'project': {"key":"Test"},
        'summary': 'Test Summary',
        'description': 'Test issue by Jira Integration'
    }
    # 统一转大写+去空格处理,避免值格式不匹配
    current_val = df.having_pet.iloc[i].strip().upper()
    if current_val == 'YES':
        new_issue[having_pet] = {'id': options[0]}
    elif current_val == 'NO':
        new_issue[having_pet] = {'id': options[1]}
    else:
        # 异常值兜底,可根据业务需求调整默认选项,避免传null
        new_issue[having_pet] = {'id': options[1]}
    new_issues.append(new_issue)

jira.create_issues(field_list=new_issues)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.14 21:54:03