Search code examples
python-3.xjira

'NoneType' object has no attribute 'name' Jira issue type


I am new to python. I am trying to pull Jira data and I keep getting a NoneType error on the singleIssue.fields.assignee.name. I understand why I am getting the error, I am just unsure how to resolve it.

columnslist = ['Story', 'Assignee']

data = []

for singleIssue in jira.search_issues(jql_str):
        fields = (
                '{}'.format(singleIssue.key),
                '{}'.format(singleIssue.fields.assignee.name)
                )
        data.append(fields)
    

dfJira = pd.DataFrame(data, columns = columnslist )

Solution

  • The reason you are getting the 'NoneType' object has no attribute 'name' Jira issue type error is because the Jira issue has no assignee to it. What you can do is check if the issue has been assigned before adding it to the fields tuple. Like so:

    columnslist = ['Story', 'Assignee']
    
    data = []
    
    for singleIssue in jira.search_issues(jql_str):
        if singleIssue.fields.assignee is None: # Check if assignee is None
          # Do what you like in the case that it is None
          fields = (
              '{}'.format(singleIssue.key),
              'No Assignee'
          )
        else:
          # Do what you like in the case that there is an assignee available
          fields = (
              '{}'.format(singleIssue.key),
              '{}'.format(singleIssue.fields.assignee.name)
          )
        data.append(fields)
    
    
    dfJira = pd.DataFrame(data, columns=columnslist)