Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jira python set custom field

I have a problem when I'm trying to set a value on a custom field in JIRA it returns me this error:

File "c:\python27\lib\site-packages\jira\resilientsession.py", line 45, in raise_on_error
r.status_code, error, r.url, request=request, response=r, **kwargs)
JIRAError: JiraError HTTP 400
    text: Operation value must be a string
    url: http://iasp091x.ia.ro.conti.de:8080/rest/api/2/issue/31424
    response headers = {'X-AUSERNAME': 'continental', 'X-ASEN': 'SEN-5132028', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'X-Seraph-LoginReason': 'OK', 'Vary': 'User-Agent', 'X-AREQUESTID': '850x418015x3', 'X-ASESSIONID': 'gv7hra', 'Connection': 'close', 'Cache-Control': 'no-cache, no-store, no-transform', 'Date': 'Mon, 01 Feb 2016 12:10:49 GMT', 'Server': 'Apache-Coyote/1.1', 'Content-Type': 'application/json;charset=UTF-8'}
    response text = {"errorMessages":[],"errors":{"customfield_11301":"Operation value must be a string"}}

The code which I'm using is this :

new_issue = jira.create_issue(project='PT', summary=issue_summary,
        description=issue_description, issuetype={'name': 'Work'})

new_issue.update(fields={'customfield_11301': [{'value':'test'}]})

Custom field 11301 is an input tag in html :

<input class="textfield text long-field" id="customfield_11301" name="customfield_11301" maxlength="254" value="" type="text">

Any ideea how to make this thing to work ?

like image 480
J.C Julien Avatar asked Oct 30 '22 10:10

J.C Julien


2 Answers

I found an solution:

def str_to_utf(value):
    if isinstance(value, str):
        return value.decode('latin1')
    return value 



new_issue.update(fields={u'customfield_11301': str_to_utf(user)}) 
like image 51
J.C Julien Avatar answered Nov 15 '22 05:11

J.C Julien


This sounds like a bug to me, raise a bug in jira-python library, with an example that can reproduce it and I will fix it asap.

The library should take care about the encoding and decoding, not you.

like image 32
sorin Avatar answered Nov 15 '22 05:11

sorin