pythonjira

Jira Python get description from SUB-Task


I am trying to get the description from a subtask in Jira. I am able to get all the information from the main task: summary, status, description, subtasks, etc... but when I pull data for a specific subtask, I am missing the description field.

ticket_data = jira.issue("PROJ-12345")
for subtask in ticket_data.fields.subtasks:
    if "generate data" in (subtask.fields.summary).lower():
        st_desc = subtask.fields.description      # ERROR
        print(subtask.raw['fields']               # Description is not a field

I thought that maybe I should try to pull only the subtask; it makes sense to me that the main task would have limited information regarding its subtasks. But when I pull the data for the subtask directly, I get the same exact information as from the main task and the description field is missing. I even tried to define that I wanted ONLY the description field.

subtask_data = jira.issue(subtask_key, fields='description')
print(subtask_data.raw['fields'])       # Returns same data - Description is not a field

I am able to create subtasks with the description without issue.

name: "subtask_1"
project: "PROJ"
summary: "Generate data for the given task"
assignee: "myself@email.com"
description: "All the data I need for the description entered here"
issuetype: "Sub-task"
parent: "PROJ-12345"

I have found several posts related to getting data from subtasks or how to create subtasks, I have even found a post on Atlassian where it appears to be a similar issue, but it's unanswered. So I thought I would ask the brilliant users of Stack Overflow for some help. :) What am I missing?

Thank you in advance!


Solution

  • In a previous edit of your own answer to the question, you showed the data of the subtasks list:

    'subtasks': [
        {
            'id': '12345678', 
            'key': 'PROJ-555', 
            'self': 'https://jira.myurl.com/issue/12345678', 
            'fields': {
                'summary': 'Generate data for the given task', 
                'status': {}, 
                'priority': {}, 
                'issuetype': {}
            }
        }
    ]
    

    You had tried to access the dictionary data at subtask.fields.key (with subtask being an element of the list), but fields and key are actually on the same "level" in the subtask dictionary.
    key is not part of the nested dictionary fields, but rather part of the subtask dictionary.

    Your only error was in the hierarchy of the nested dictionaries.
    I usually try to avoid such error by first printing the full object/list/dict once, and then homing in on the actual data I need to extract for my use case. Doing that step by step, prevents errors such as this one.