2

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.

maxx777
  • 1,320
  • 1
  • 20
  • 37

1 Answers1

1

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)
nickm
  • 5,936
  • 1
  • 13
  • 14
  • `https://community.rallydev.com/slm/webservice/v2.0/Task?fetch=FormattedID,State,Name&query=(Iteration.Name%20=%20%222014%20november%22)&order=FormattedID&pagesize=200&start=1` Gave me 0 results. As did the interactive query boxes on the wsapi documentaion page. Tried your code (replaced the iteration name with \"2014 november\") and got 0 qualifying tasks. Also tested by iteration reference. Same again. So i'm kind of lost. Could it be a limitation on the users of community edition? Doesn't sound plausible, but i'm all out of ideas. – user2451040 Dec 15 '14 at 09:43
  • If your WS API query returns 0 results it has nothing to do with python code. It means that there are either no artifacts scheduled for iteration 2014 november or the name of the iteration is spelled wrong(e.g. extra or missing space between 2014 and november". Query by iteration.ObjectID (unless you've done it already when you said by iteration ref) and see if you get the results you expect. To get the ObjectID of the iteration go to the details page of it and use the last string of numbers in the URL, e.g. https://rally1.rallydev.com/#/1234/detail/iteration/7890 ObjectID is 7890. – nickm Dec 15 '14 at 15:49