Unable to extract all feature data for a project using pyral's rest api python

361 Views Asked by At

I'm trying to read all feature data for a project in Rally using pyral module. The total result set count is 1358 and the script throws error as mentioned below after reading some 700 records.

rally1 = Rally(entity='PortfolioItem_Feature',server='rally1.rallydev.com',fetch=True, user='xxx', password='', workspace='xxx/yyy', project='ABC')
features = rally1.get('Feature',fetch="True",pagesize=2000,start=0,limit=5000)

for feature in features:
    #a=pd.DataFrame(feature)
    print(feature.details())

OUTPUT:

PortfolioItem/Feature result set, totalResultSetSize: 1358, startIndex: 1  pageSize: 2000  current Index: 0
I'm getting the following errors:

File "C:\Users\nis\AppData\Roaming\Python\Python38\site-packages\pyral\entity.py", line 397, in details
    (attr_name, cln, value.oid, value.UserName, value.DisplayName)
  File "C:\Users\nis\AppData\Roaming\Python\Python38\site-packages\pyral\entity.py", line 139, in __getattr__
    raise UnreferenceableOIDError("%s OID %s" % (rallyEntityTypeName, self.oid))
pyral.entity.UnreferenceableOIDError: User OID 44012386960

So, I have following questions:

  1. How can I fix this error, meaning skip reading that particular field for the feature attributes or replace that with empty result set.
  2. How can I convert the (a) <class 'pyral.rallyresp.RallyRESTResponse'> (b) PortfolioItem/Feature result set to dataframe without getting the error as mentioned above.

I am using the below code and this script too reads approx. 700 records and throws the same error as mentioned above. I tried using error handing still it stops reading at the point where it encounters error. Any help will be greatly appreciated.

r=pd.DataFrame()
for feature in features:
 a= {
 'OID': feature.oid,
 'FeatureID':feature.FormattedID,
 'Creation_Date': feature.CreationDate,
  'Project_Name': feature.Project.Name,
  'AcceptedLeafStoryPlanEstimateTotal':feature.AcceptedLeafStoryPlanEstimateTotal,
  'AcceptedLeafStoryPlanEstimateTotal':feature.AcceptedLeafStoryPlanEstimateTotal,
  'Feature_payload':feature._ref,
  'Created by':feature.CreatedBy.DisplayName
 }
 #print(a.keys())
 #print(a.values())
 r=r.append(a,ignore_index=True,sort=False)
 print(r)
2

There are 2 best solutions below

0
eemz On

Looks to me like the object with id 44012386960 is broken so you'll have to skip it.

for feature in features:
    if feature.oid == 44012386960:
        continue
    print(feature.details())

I'm assuming that your error is a bad featureoid because it also happens in your second loop which only uses feature.oid but it's also possible that feature.CreatedBy is the problem because your error message suggests that it's a bad user oid. In that care my suggestion would be to print feature.CreatedBy.oid in your loop to find the bad one and change my if to if feature.CreatedBy.oid == 44012386960: continue

1
nischalkumar On

I resolved the issue using ternary operators in python as shown below:

feature_name = '' if feature.Feature is None else feature.Feature.Name

The issue was whenever Rally rest api was unable to reference the oid for a particular feature that caused an error.