Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,470
Community Members
 
Community Events
184
Community Groups

jira.resource.issue object has no attribute 'fields'

Asaf Dinchman
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!
May 14, 2023

Hi , I using the following python code as infra :

from jira import JIRA
from qa_auto_infra_tools.Tools.Logger.SimpleLogger import logger
from qa_auto_infra_tools.Tools.SyncTests.SyncTestsToDB.Helpers.Properties import CommonProperties
import json
import os
import datetime


class JiraOperations:
custom_field_dict = {
"Rally Creation Date": "customfield_10134",
"Rally Created By": "customfield_10135",
"Rally FormattedID": "customfield_10136",
"Rally Project": "customfield_10142",
"Rally Feature": "customfield_10146",
"Rally Owner": "customfield_10147",
"Rally Parent": "customfield_10148",
"Product Name": "customfield_10035",
"Method": "customfield_10154",
"Reported On Version": "customfield_10108",
"Problem Origin": "customfield_10104",
"Closed Status": "customfield_10067",
"First Resolved Date": "customfield_10097",
"Jira ID": "customfield_10193",
"Path": "customfield_10160"
}

def __init__(self):
self.jira_properties = json.load(open(os.path.join(os.path.dirname(__file__), 'jira_properties.json')))
self.url = self.jira_properties['url']
self.common_properties = CommonProperties
self.user_name = self.jira_properties['user_name']
self.password = self.jira_properties['password']
self.jira = self.init_jira()

def init_jira(self):
"""

Returns: an instance of a JIRA object

"""
return JIRA(server=self.url, basic_auth=(self.user_name, self.password))


def extract_issue_info(self, issue):
project = self.jira.project(self.common_properties.JIRA_PROJECT_KEY.strip())

issue_info = dict()
issue_info['TYPE'] = 'TestCase'
issue_info['TS_TEST_ID'] = issue.id
issue_info['TS_NAME'] = issue.key
issue_info['TS_USER_01'] = ','.join([tc_tag for tc_tag in list(issue.fields.labels)]) if len(
issue.fields.labels) > 0 else None
issue_info['TS_STATUS'] = None
issue_info['TS_RESPONSIBLE'] = issue.fields.creator.displayName
issue_info['TS_TYPE'] = getattr(issue.fields, JiraOperations.custom_field_dict['Method']).value \
if getattr(issue.fields, JiraOperations.custom_field_dict['Method']) else 'Automated'
issue_info['TS_SUBJECT'] = project.id # Should be Test Folder
issue_info['TS_LAST_UPDATE_DATE'] = datetime.datetime.strptime(issue.fields.updated.split('T')[0], '%Y-%m-%d')
issue_info['TS_BUG_IDS'] = None
issue_info['TS_CREATION_DATE'] = datetime.datetime.strptime(issue.fields.created.split('T')[0], '%Y-%m-%d')
issue_info['TS_DESCRIPTION'] = issue.fields.description
issue_info['TESTS'] = None
issue_info['TS_CLASS_NAME'] = getattr(issue.fields, JiraOperations.custom_field_dict['Path']).value
return issue_info

def get_all_tests(self, project_name, fields):
issues = []
issues_info = []
i = 0
chunk_size = 100
while True:
chunk = self.jira.search_issues(f'project = {project_name} AND issuetype = Test', startAt=i, maxResults=chunk_size, fields=fields)
i += chunk_size
issues += chunk.iterable
if i >= chunk.total:
break
for issue in issues:
issues_info += self.extract_issue_info(issue)
return issues_info

 when I execute my code I get:

raise AttributeError(
AttributeError: <class 'jira.resources.Issue'> object has no attribute 'fields' ('Issue' object is not subscriptable)

when I inspect the object in debug I see that indeed the object doesn't have those fields , only id , key , url as seen in pic

image.png

how do I extract all this info ?h

0 answers

Suggest an answer

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

Atlassian Community Events