Rally python REST: Query all tasks from chosen iteration

2.2k views Asked by At

I'm trying to query all tasks from a specific iteration using the python toolkit for the rally REST API. The iteration will be chosen at run-time.

However I have been unable to set up the right query. I feel like i'm missing something small but important here.

This is the code:

query_criteria = 'Iteration.Name = "2014 november"'
response = rally.get('Task', fetch=True, query=query_criteria)
if response.errors:
    sys.stdout.write("\n".join(response.errors))
    sys.exit(1)
for Task in response:
    if getattr(Task,"Iteration"):
            print "%s %s" % (Task.Name,Task.Iteration.Name)

It will receive 0 rows in response.

If I remove , query=query_criteria and fetch all tasks, then i can see that there are tasks where the Task.Iteration.Name value is 2014 November.

The query does not give an error so I assume that the values of related objects (task->Iteration) are able to be included in the query. Yet I receive 0 rows in response.

Could the reason be that some tasks do not seem to be attached to an iteration?

One solution would be to fetch all tasks and then filter them afterwards. But that seems dirty.

1

There are 1 answers

2
nickm On

If you query directly in the WS API in the browser do you get results?

https://rally1.rallydev.com/slm/webservice/v2.0/task?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12352608129&query=(Iteration.Name%20%3D%20%22my%20iteration%22)&pagesize=200

I verified that this code works with pyral 1.1.0, Python 2.7.0 and requests-2.3.0 - it returns all tasks of workproducts(e.g. user stories and defects) assigned to an iteration. I tested 3 queries: by state, by iteration reference and by iteration name (the first two are commented out in the code).

#!/usr/bin/env python

#################################################################################################
#
#  showitems -- show artifacts in a workspace/project conforming to some common criterion
#
#################################################################################################

import sys, os
from pyral import Rally, rallyWorkset, RallyRESTAPIError

#################################################################################################

errout = sys.stderr.write

#################################################################################################

def main(args):
    options = [opt for opt in args if opt.startswith('--')]
    args    = [arg for arg in args if arg not in options]
    server, username, password, apikey, workspace, project = rallyWorkset(options)
    if apikey:
        rally = Rally(server, apikey=apikey, workspace=workspace, project=project)
    else:
        rally = Rally(server, user=username, password=password, workspace=workspace, project=project)
    rally.enableLogging("rally.history.showitems")

    fields    = "FormattedID,State,Name"
    #criterion = 'State != Closed'
    #criterion = 'iteration = /iteration/20502967321'
    criterion = 'iteration.Name = \"iteration 5\"'

    response = rally.get('Task', fetch=fields, query=criterion, order="FormattedID",
                                   pagesize=200, limit=400)

    for task in response:
        print "%s  %s  %s" % (task.FormattedID, task.Name, task.State)

    print "-----------------------------------------------------------------"
    print response.resultCount, "qualifying tasks"

#################################################################################################
#################################################################################################

if __name__ == '__main__':
    main(sys.argv[1:])
    sys.exit(0)