Search code examples
pythonpython-redmine

Get the list of subtasks of an issue using python redmine module


I am writing a python script using python-redmine module to automate the issue creation in Redmine tool for project task tracking.

With the help of python-redmine documentation, it was quite easy to create issues and subtask under them. Also it is straight forward to get the parent issue of a given issue using 'parent' attribute.

Now, for a given issue, I would like to get the list of associated subtasks and then extract attributes like, start and end date of the subtask to consolidate to the main issue.

I found a lengthy solution as given below.

>>>from redmine import Redmine
>>>projt = redmine.project.get('redmine_test')
>>>projt.issues
>>> for iss in projt.issues:
...   try:
...     print(iss.id,':',iss.parent)
...   except:
...     pass
...
4341 : 4335
4340 : 4335
4339 : 4335
4299 : 4297
4298 : 4297
4212 : 4211
4211 : 4187

From this subtasks of a issue can be listed, for example, the issue 4335 has subtasks 4339, 4340 and 4341.

Is there any other simpler way?


Solution

  • You have 2 options to get children tasks of the task:

    1) This is the preferred option because it will return all the subtasks in one call:

    issue = redmine.issue.get(105, include='children')
    issue.children
    <redmine.resultsets.ResourceSet object with Issue resources>
    

    2) You can use an on demand includes:

    issue = redmine.issue.get(105)
    issue.children
    <redmine.resultsets.ResourceSet object with Issue resources>
    

    The difference is that in the first case you'll get the subtasks in one call to the Redmine, in the second case a second call will be made to Redmine when you'll begin working with issue.children.

    For your example you'll have to use the second option because you're retrieving all issues of a project and not a single one.