Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues.update(labels=[]) fails with JIRAError #226

Closed
els-pnw opened this issue Jun 10, 2016 · 5 comments · Fixed by #787
Closed

issues.update(labels=[]) fails with JIRAError #226

els-pnw opened this issue Jun 10, 2016 · 5 comments · Fixed by #787
Labels

Comments

@els-pnw
Copy link

els-pnw commented Jun 10, 2016

When attempting to update labels using the example from https://pythonhosted.org/jira/ a JIRAError and stacktrace are returned.

# You can update the entire labels field like this
issue.update(labels=['AAA', 'BBB'])

JIRAError Traceback (most recent call last)
in ()
----> 1 issue.update(labels=['AAA', 'BBB'])

/usr/lib/python2.7/site-packages/jira-1.0.7-py2.7.egg/jira/resources.pyc in update(self, fields, update, async, jira, **fieldargs)
449 fields_dict[field] = value
450
--> 451 super(Issue, self).update(async=async, jira=jira, fields=data)
452
453 def add_field_value(self, field, value):

/usr/lib/python2.7/site-packages/jira-1.0.7-py2.7.egg/jira/resources.pyc in update(self, fields, async, jira, **kwargs)
192
193 r = self._session.put(
--> 194 self.self, data=data)
195 if 'autofix' in self._options and
196 r.status_code == 400:

/usr/lib/python2.7/site-packages/jira-1.0.7-py2.7.egg/jira/resilientsession.pyc in put(self, url, *_kwargs)
153
154 def put(self, url, *_kwargs):
--> 155 return self.__verb('PUT', url, *_kwargs)
156
157 def delete(self, url, *_kwargs):

/usr/lib/python2.7/site-packages/jira-1.0.7-py2.7.egg/jira/resilientsession.pyc in __verb(self, verb, url, retry_data, *_kwargs)
143 if exception is not None:
144 raise exception
--> 145 raise_on_error(response, verb=verb, *_kwargs)
146 return response
147

/usr/lib/python2.7/site-packages/jira-1.0.7-py2.7.egg/jira/resilientsession.pyc in raise_on_error(r, verb, *_kwargs)
53 error = r.text
54 raise JIRAError(
---> 55 r.status_code, error, r.url, request=request, response=r, *_kwargs)
56 # for debugging weird errors on CI
57 if r.status_code not in [200, 201, 202, 204]:

When I use the second option

issue.fields.labels.append(u'new_text')
issue.update(fields={"labels": issue.fields.labels})

All works, and this applies to a issue that currently has labels = None

@LolithaRatnayake
Copy link

This issue is valid. Please remove below from documentation.
# You can update the entire labels field like this issue.update(labels=['AAA', 'BBB'])

it will give an error like

Can not instantiate value of type [simple type, class com.atlassian.jira.rest.api.issue.FieldOperation] from JSON String; no single-String constructor/factory method (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean["update"]

@ghost
Copy link

ghost commented Jul 20, 2017

I am also seeing errors given the first method, and also for the second method:

issue.fields.labels.append(u'LABEL1')
issue.update(fields={"labels": issue.fields.labels})

yielding:

JIRAErrorTraceback (most recent call last)
<ipython-input-73-3251eb23d1f9> in <module>()
      1 issue.fields.labels.append(u'LABEL1')
----> 2 issue.update(fields={"labels": issue.fields.labels})

/home/soc-monitor/anaconda2/lib/python2.7/site-packages/jira/resources.pyc in update(self, fields, update, async, jira, notify, **fieldargs)
    478                 fields_dict[field] = value
    479 
--> 480         super(Issue, self).update(async=async, jira=jira, notify=notify, fields=data)
    481 
    482     def add_field_value(self, field, value):

/home/soc-monitor/anaconda2/lib/python2.7/site-packages/jira/resources.pyc in update(self, fields, async, jira, notify, **kwargs)
    227 
    228         r = self._session.put(
--> 229             self.self + querystring, data=data)
    230         if 'autofix' in self._options and \
    231                 r.status_code == 400:

/home/soc-monitor/anaconda2/lib/python2.7/site-packages/jira/resilientsession.pyc in put(self, url, **kwargs)
    154 
    155     def put(self, url, **kwargs):
--> 156         return self.__verb('PUT', url, **kwargs)
    157 
    158     def delete(self, url, **kwargs):

/home/soc-monitor/anaconda2/lib/python2.7/site-packages/jira/resilientsession.pyc in __verb(self, verb, url, retry_data, **kwargs)
    144         if exception is not None:
    145             raise exception
--> 146         raise_on_error(response, verb=verb, **kwargs)
    147         return response
    148 

/home/soc-monitor/anaconda2/lib/python2.7/site-packages/jira/resilientsession.pyc in raise_on_error(r, verb, **kwargs)
     54                 error = r.text
     55         raise JIRAError(
---> 56             r.status_code, error, r.url, request=request, response=r, **kwargs)
     57     # for debugging weird errors on CI
     58     if r.status_code not in [200, 201, 202, 204]:

JIRAError: JiraError HTTP 400 url: https://itjira.company.com/rest/api/2/issue/559504
	text: Field 'labels' cannot be set. It is not on the appropriate screen, or unknown.
	
	response headers = {'X-AUSERNAME': 'test-user, 'X-AREQUESTID': '447x3678045x2', 'X-Content-Type-Options': 'nosniff', 'Transfer-Encoding': 'chunked', 'X-Seraph-LoginReason': 'OK', 'X-ASESSIONID': 'klp8t6', 'Server': 'Apache', 'Connection': 'close', 'Cache-Control': 'no-cache, no-store, no-transform', 'Date': 'Thu, 20 Jul 2017 12:27:05 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'X-ASEN': 'SEN-2208072'}
	response text = {"errorMessages":[],"errors":{"labels":"Field 'labels' cannot be set. It is not on the appropriate screen, or unknown."}}

@tlau
Copy link

tlau commented Sep 26, 2017

Confirmed. I also had the error using the first method (issues.update(labels=...)). The second method (issue.update(fields=...)) did work for me.

@sandeepnavale
Copy link

Hi
I am getting "AttributeError: 'str' object has no attribute 'fields'" when i do below
issue.update(fields={"labels": issue.fields.labels})

any idea how to resolve this?
I tried issues.update(labels. .. also. but getting
"JIRAError: JiraError HTTP 400 "

@hdost hdost added the bug label Jun 29, 2018
@wesinator
Copy link
Contributor

wesinator commented May 8, 2019

This works: issue.update(fields={"labels": ['AAA', 'BBB']})
The labels array has to be encapsulated in the fields keyword arg.

Submitting a docs PR to correct the bad example

ssbarnea pushed a commit that referenced this issue May 29, 2019
labels must be encapsulated in fields arg

close #226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants