I would like to clone an issue and it's subtasks via python automation. In order to do this, I read in the story data and create a new story. Next, I read the subtasks and create new subtasks and then add them to the new story. Each subtask has a description of the task to be completed.
When pulling the data for a subtask, there is no description, labels, components or other fields.
When you pull the fields for a subtask, this is all I get. Removed some info and replaced with ***
subtask = jira.issue(subtask_key)
json_fields = subtask.raw['fields']
print(json.dumps(json_fields, indent=3))
"fields": {
"summary": "Test Summary",
"status": {
"self": "***",
"description": "New issue that needs to be triaged.",
"iconUrl": "***",
"name": "Screen",
"id": "1",
"statusCategory": {
"self": "***",
"id": 2,
"key": "new",
"colorName": "blue-gray",
"name": "To Do"
},
"priority": {
"self": "*",
"iconUrl": "*",
"name": "Major",
"id": "3"
},
"issuetype": {
"self": "*",
"id": "5",
"description": "The sub-task of the issue",
"iconUrl": "*",
"name": "Sub-Task",
"subtask": true,
"avatarId": 18416
}
}
# This was helpful. For me,
client.issue(key)
# works for any jira issue, but
issue = client.issue(key)
for subtask in issue.fields.subtasks:
print(json.dumps(subtask.raw, indent=2)) # this has limited fields
subtask = client.issue(subtask.key)
print(json.dumps(subtask.raw, indent=2)) # this has all issue fields
Hi @William Briere ,
Do I assume correctly that you get the information via Rest API?
If so and you calling the issue endpoint it´s not delivering ALL fields by default. There is a query parameter to retreive all fields of the issue. See the link below to the documentation:
Hope I could follow your requirement correctly and this was helpful.
Best
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm using this JIRA python library. https://jira.readthedocs.io/examples.html#issues I'm not sure if there's any way to utilize the parameter through this library or if I'd need to formulate a new REST query in python just to pull that data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Stefan Salzl
Are you sure? The v3 Get issue endpoint returns ALL fields, by default, and the fields parameter is just for being more specific about the list of fields to return.
Hello @William Briere
You are using a third party Python library whose functions and behaviours are specific to it. That library does support the use of a fields parameter with the issues object:
If you only want a few specific fields, save time by asking for them explicitly:
issue = jira.issue('JRA-1330', fields='summary,comment')
Just like the native REST API endpoint, ALL the issue's fields are returned by default, and the fields parameter is for specifying only specific fields be returned.
Have you confirmed that the Sub-task issue type hasn't been specifically configured to not have fields such as labels, components etc? I've worked in plenty of Jira environments where the Sub-tasks have been 'stripped down' exactly like that via a custom screen scheme for certain projects.
I'd suggest you first test your query, in a plain request to the specific REST API endpoint using a test tool like Postman to first confirm the endpoint is working as expected to rule that out.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the hint. My bad....I just had the link in my bookmarks that was pointing to v2 🙈
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad you mentioned v2 because it made me look at my endpoint and it only supports v2 at the moment. Either way, I did a direct REST API call in my browser and it does provide the description, components, and labels, so it must be something to do with the python library... I tried this:
subtask = jira.issue(subtask_key, fields='summary,description,labels,components')
And it still didn't provide description, labels, or components... I'll try digging futher.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @William Briere ,
It's been a while since I last you the Python API, but you should be able to use the resources API to directly address specific endpoints: https://jira.readthedocs.io/api.html#jira-resources-module
That way, you should be able to get to the v3 API albeit less comfortable than with the built-in functions from the jira.client module.
Hope that helps,
Oliver
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've done more digging and I can't figure out why I'm not getting returned all of the fields. My company's JIRA installation doesn't support v3, but I'm not sure that's the issue due to the fact that the v2 rest API shows everything when I access it directly through the browser. Is there anything else in the JIRA python library that might be causing what is returned for subtasks to be reduced?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I'm now convinced that this has something to do with cache because it's not making an individual call to the server for each subtask as that information was already pulled when I requested information from the parent.
Is there a method to delete the cache?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you trying to retrieve the payload from the parent and extract the subtask‘s description from that payload?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is my method.
1. Pull Story
2. Get keys of subtasks from story
3. Pull each subtask individually using key
I can see that there are no requests being sent when I try to pull each subtask individually. I put a log output line in the resources file to see the headers and parameters and neither log line is hit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmmm.....that sounds really weird 🙄
Unfortunately I‘m not familiar with python and the library „only“ some API stuff. So I‘m sorry I don‘t have any further ideas 🙈
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @William Briere
You haven't advised how you are 'reading the data' or 'pulling the data'. You have said you are using Python, so can it be assumed you're interacting with the REST API somehow? If so, which specific endpoints are you accessing and what is the actual request (code) you are sending to that endpoint. Are you using a native Python library / module, or a third party one?
Also, you haven't advised which type or version of Jira you're accessing. Server, Cloud or Data Centre? Software or Service Management? Please add that information as tags to your question.
Sub-tasks are just like Stories in that they are issues. If you query the appropriate issue endpoints, you should get back mostly identical results.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.