Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update Parent of Subtask through Python Jira API

Ahmad Sidawi
Contributor
July 22, 2022

Hi, 

 

According to this: https://jira.atlassian.com/browse/JSWCLOUD-22718

its now possible to update the Parent of a subtask through the API. Does anyone know how to do this through Python? I've tried the following but no dice:

 

sub_task_issue.update(parent=test_issue.key)
sub_task_issue.update(fields = {'parent': test_issue})
sub_task_issue.update(parent = test_issue)
 

 

I'm getting errors like: 

 response text = {"errorMessages":[],"errors":{"parent":"data was not an object"}} 

or 

TypeError: Object of type Issue is not JSON serializable

 

Thanks in advance!

 

2 answers

1 accepted

2 votes
Answer accepted
Ahmad Sidawi
Contributor
July 25, 2022

This turned out to be the correct syntax: 

 

sub_task_issue.update(fields = {'parent': {'key': str(test_issue.key)}})

andrew_pieri
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 5, 2025

I can't even begin to tell you how much this little line helped. Every other key:value pair in our code uses "value" or "name" for the key. But for some reason (probably because parent is newer), the key for parent is LITERALLY "key".

Thanks again lol.

Like Ahmad Sidawi likes this
0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2022

Whatever Python library you are using, it is not sending the right data to Jira.

Either you're not feeding the function valid data, or the library has a bug.  Whichever it is, the JSON that the REST call is sending is malformed and Jira can't read it.

What is providing the function sub_task_issue.update ?

Ahmad Sidawi
Contributor
July 22, 2022

https://pypi.org/project/jira/

 

I'm using the above, i think i might just have the 'update' syntax wrong for updating Parent.

 

I've used it before to update fields in Jira like so:

sub_task_issue.update(fields = {'customfield_12389': {'value': "XYZ"}})
Ahmad Sidawi
Contributor
July 22, 2022
def update(
self,
fields: Optional[Dict[str, Any]] = None,
async_: Optional[bool] = None,
jira: "JIRA" = None,
notify: bool = True,
**kwargs: Any,
):



Ahmad Sidawi
Contributor
July 22, 2022

Figured it out eventually :

 

sub_task_issue.update(fields = {'parent': {'key': str(test_issue.key)}})
Dharmraj Chauhan February 6, 2023

Hi, I am using JIRA library in python for the automation.
And, I am using below code to create child issue using parent issue's key, but I am getting the error.

parent_issue_data = {
        "project": {"key": project_name},
        "summary": main_task,
        "issuetype": {"name": "Task"},
        }
parent_issue = jira.create_issue(fields=parent_issue_data)
child_issue_data = {
"project": {"key": project_name},
        "summary": main_task,
        "issuetype": {"name": "Task"},
"parent": {'key': 'ANTAR-28'}       
}
child_issue = jira.create_issue(fields=child_issue_data)
Please, can you guide me how I have to do it.

I just want to attach the sub task under the parent task.
Ahmad Sidawi
Contributor
February 6, 2023

What error do you get?

Like Dharmraj Chauhan likes this
Dharmraj Chauhan February 6, 2023
AttributeError Traceback (most recent call last)

File c:\raaj\python\JiraAutomation\.reqenv\lib\site-packages\atlassian\rest_client.py:436, in AtlassianRestAPI.raise_for_status(self, response)

434 else:

435 error_msg = "\n".join(

--> 436 j.get("errorMessages", list()) + [k.get("message", "") for k in j.get("errors", dict())]

437 )

438 except Exception as e:

File c:\raaj\python\JiraAutomation\.reqenv\lib\site-packages\atlassian\rest_client.py:436, in <listcomp>(.0)

434 else:
435 error_msg = "\n".join(
--> 436 j.get("errorMessages", list()) + [k.get("message", "") for k in j.get("errors", dict())]
437 )
438 except Exception as e:

AttributeError: 'str' object has no attribute 'get'

During handling of the above exception, another exception occurred:
HTTPError Traceback (most recent call last)
Cell In[48], line 59
---> 59 child_issue = jira.create_issue(
...
1018 )
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)

HTTPError: 400 Client Error: Bad Request for url: https://raajchauhan.atlassian.net/rest/api/2/issue?updateHistory=false


Thanks for your responce.

Dharmraj Chauhan February 6, 2023

My issue is resolved.

They changed the issue type parameter syntax.

 

My previous code:

"issuetype": {"name": "Sub-task"},

 

And, Here is my current working code:

"issuetype": {"name": "Subtask"},

 

Thank you.

Like Ahmad Sidawi likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events