How to directly extract all attributes from a single pyral.entity.Defect?
Linlin-Li-1 opened this issue · 5 comments
When I ran the get command to fetch defects data through Pyral, if there are more than one defects from the response, then it will return a 'Defect result set' object and I can extract all information about defects through "defect.content['QueryResult']['Results']".
However, if there are only one defects from the response, then it will return a 'pyral.entity.Defect' object and I am confused on how to extract all information from this object. I would like to get a similar JSON that contains all attributes about the defect.
Thank you in advance.
Here's what I ran today using pyral 1.5.2 and Python 3.9.5:
with a qualifiers value that ensures multiple Defects satisfy the condition, ie "CreationDate >= 2021-09-01T12:30:00Z"
response = rally.get(entity_name, fetch=True, query=qualifiers, order='CreationDate')
AND
with a qualifiers value that ensures only a single Defect satisfies the condition, ie "FormattedID = DE54348"
response = rally.get(entity_name, fetch=True, query=qualifiers)
in both cases, the response is a RallyRESTResponse instance which has a few useful attributes on its own, eg, headers, status_code, errors, warnings and others.
The intent with RallyRESTResponse is that it be used as an iterator to obtain instances (0, 1 or more) of the entity type provided in the get request.
While you certainly can dig into the response instance and obtain the response.content, as you've seen, you have to be
cognizant of whether there is nothing, one thing or many things. Using RallyRESTResponse instance as designed insulates you from having to deal with those different scenarios.
Once you have an instance or instances from the response, you can call instance.attributes() to get a list of the names of the instance's Attributes and you can call instance.details() to get printable output showing all the attributes and their current values.
Hope this helps.
Thanks Kip.
However, the response from "instance.details()" is different from "defect.content['QueryResult']['Results']". For example, I can only obtain the attribute "ALMAssignedTo" from instance.details()", but I can obtain "c_ALMAssignedTo" from "defect.content['QueryResult']['Results']".
More specifically, for those JSON attributes, such as 'Workspace', 'SubmittedBy', 'Owner', etc., I need to manually convert it to JSON by adding each of the key-value pairs within the JSON.
There are a total of over 70 attributes are under different formats between "instance.details()" and "defect.content['QueryResult']['Results']", which will require a lot of effort to match to the same format.
Could you let me know if there are some other ways to get them into the same format?
Thank you!
Having some bigger context would probably help me to understand what you are trying to accomplish. What business problem are you attempting to address in which Rally data is needed? Is it used in conjunction with data from other sources?
Is it used for analysis, comparison, trending, decision making, progress tracking or X? How frequently is the Rally data consulted for these purposes, weekly, daily, hourly, on-demand etc.? What kind of range or specificity in the data is required? A wide set or narrow set in terms of artifact types? likewise for workspaces / projects, date range, owners, states , etc.?
The Rally data is currently not used in conjunction with data from other sources. We are performing analysis and developing models on Rally data to support the decision-making process. For this reason, Rally data is extracted every 10 minutes. More specifically, we will fetch Rally data based on "LastUpdateDate" every 10 minutes. The number of Rally defects under our consideration is about 28K. In this case, we do need to get defect data in the same format for one defect and multiple defects.
Thank you for the information on your context! The sequence that I would propose to address the overall problem that you are trying solve consists of 3 items.
- Figure out how to get the set of defects from a query (ie, rally.get operation) in a consistent representation.
- Understand the access to attributes necessary for your purposes
- Consider approaches to retrieving and handling defect Revisions efficiently
As mentioned in a prior post, I was not able to reproduce the situation you described when the result of a rally.get was 1 item versus multiple items. Could you provide the pertinent portions of the code you run that illustrates the problem in your environment? Certainly, you should fuzz any sensitive or customer specific data used in your query. For example, "fuzzing" a specific defect FormattedID or an Owner value while still conveying the query conditions essence would be very helpful.
Something along the lines of this to obtain a single instance: qualifiers = 'Description = "--%%very unique text fragment%%-" fed to rally.get('Defect', fetch=True, query=qualifiers, ...) and this for obtaining multiple defects: qualifiers = 'CreationDate >= 2021-10-22T08:00:00.000Z'. Having something that I can use to reproduce the situation you encounter would help immensely. Code that you use to qualify the query and access the results will help clarify.