我正在尝试使用jira-python更新基本上是版本字段的自定义字段。
我可以轻松获取项目的版本集,找到要设置的正确版本,但是我坚持的地方实际上是在更新此自定义版本字段。
以下是一些相关代码:
pl = jira.project('PL')
versions = jira.project_versions(pl)
# assume the function below returns list of issues I want to update
issues = query_resolved_issues()
for i in issues:
# assume this function selects the right version in versions
update_version = get_right_version(i, versions)
i.update(customfield_10303=update_version)
更新行发生错误:
File "/usr/local/lib/python2.7/site-packages/jira/resources.py", line 352, in update
super(Issue, self).update(async=async, jira=jira, fields=data)
File "/usr/local/lib/python2.7/site-packages/jira/resources.py", line 148, in update
data = json.dumps(data)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 243, in dumps
return _default_encoder.encode(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <JIRA Version: name=u'IT79 - 6/11/15', id=u'12902'> is not JSON serializable
我确保存储在自定义字段中的值应该是版本对象本身(就像我在JIRA上的问题上手动设置发布版本并获取customfield_10303的值在这种情况下我返回相同的对象类型正如我试图在更新期间设置对象。任何人都有想法?
答案 0 :(得分:2)
基于How do you set the fixVersion field using jira-python,它应该是:
i.update(fields={ 'customfield_10303' : [{'id': update_version['id']}] })