JIRA for Python does not pull all fields for subtask

William Briere September 14, 2022

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
   }
}

2 answers

0 votes
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 14, 2022

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:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get

 

Hope I could follow your requirement correctly and this was helpful.

Best
Stefan

William Briere September 14, 2022

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.

David Bakkers
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.
September 14, 2022

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.

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 14, 2022

@David Bakkers 

Thanks for the hint. My bad....I just had the link in my bookmarks that was pointing to v2 🙈

William Briere September 14, 2022

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. 

Oliver Siebenmarck _Polymetis Apps_
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.
September 14, 2022

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

William Briere September 15, 2022

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?

William Briere September 15, 2022

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?

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 15, 2022

Are you trying to retrieve the payload from the parent and extract the subtask‘s description from that payload?

William Briere September 16, 2022

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.

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 16, 2022

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 🙈

0 votes
David Bakkers
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.
September 14, 2022

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.

Suggest an answer

Log in or Sign up to answer