Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question of Issues #27

Closed
jeonghanlee opened this issue Apr 2, 2014 · 4 comments
Closed

question of Issues #27

jeonghanlee opened this issue Apr 2, 2014 · 4 comments
Assignees
Labels

Comments

@jeonghanlee
Copy link

Hi,

I would like to access "parent_issued_id" in a single issue in order to collect Issues according to their parent Issues. However, I cannot find that
attributes in Issue. I am a novice of Python and Redmine. Here is my code

>>>from redmine import Redmine
>>>redmine = Redmine(g_redmine_url, key=g_redmine_key, requests={'verify': False})
>>>project = redmine.project.get(g_redmine_project)
>>>issues  = list(project.issues)
>>> dir(issues[0])
[u'assigned_to', 'attachments', u'author', u'category', 'changesets', 'children', u'created_on', u'description', u'done_ratio', u'due_date', u'id', 'journals', u'priority', u'project', 'relations', u'start_date', u'status', u'subject', 'time_entries', u'tracker', u'updated_on', 'watchers']
>>> fi=issues[0]
>>> fi.id
206
>>> fi.assigned_to
<redmine.resources.User #16 "Jeong Han Lee">
>>> fi.attachments
<redmine.resultsets.ResourceSet object with Attachment resources>
>>> fi.author
<redmine.resources.User #16 "Jeong Han Lee">
>>> fi.category
<redmine.resources.IssueCategory #14 "Control SW">
>>> fi.changesets
[]
>>> fi.created_on
datetime.datetime(2014, 4, 2, 2, 5, 8)
>>> fi.description
u'test'
>>> fi.done_ratio
20
>>> fi.due_date
datetime.date(2014, 4, 17)
>>> fi.id
206
>>> fi.journals
<redmine.resultsets.ResourceSet object with IssueJournal resources>
>>> fi.priority
<redmine.resources.Enumeration #4 "Normal">
>>> fi.project
<redmine.resources.Project #52 "Fouth Year Plan">
>>> fi.relations
<redmine.resultsets.ResourceSet object with IssueRelation resources>
>>> fi.start_date
datetime.date(2014, 4, 2)
>>> fi.status
<redmine.resources.IssueStatus #2 "In Progress">
>>> fi.subject
u'test issue for redmine python script'
>>> fi.time_entries
<redmine.resultsets.ResourceSet object with TimeEntry resources>
>>> fi.tracker
<redmine.resources.Tracker #13 "Activity">
>>> fi.updated_on
datetime.datetime(2014, 4, 2, 2, 5, 8)
>>> fi.watchers

As you expect,

>>> fi.parent_issue_id
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/redmine/resources.py", line 357, in __getattr__
    return super(Issue, self).__getattr__(item)
  File "/usr/local/lib/python2.7/dist-packages/redmine/resources.py", line 166, in __getattr__
    return self._action_if_attribute_absent()
  File "/usr/local/lib/python2.7/dist-packages/redmine/resources.py", line 264, in _action_if_attribute_absent
    raise ResourceAttrError()
redmine.exceptions.ResourceAttrError: Resource doesn't have the requested attribute

I was trying to look at resource.py, and realized quickly to ask this question to developers.

Thanks,
Han

@maxtepkeev
Copy link
Owner

Hello, Han!

If you need to access the parent issue of the issue you have to use the parent attribute of the issue resource, BUT it's only available ONLY if the issue has a parent issue, e.g.:

>>> from redmine import Redmine
>>> redmine = Redmine('http://your-redmine.url', username='jsmith', password='foobar')
>>> issue = redmine.issue.get(12345)
>>> dir(issue) 
['attachments',
 'author',
 'changesets',
 'children',
 'created_on',
 'custom_fields',
 'description',
 'done_ratio',
 'id',
 'journals',
 'parent', <---------- here it is
 'priority',
 'project',
 'relations',
 'spent_hours',
 'start_date',
 'status',
 'subject',
 'time_entries',
 'tracker',
 'updated_on',
 'watchers']
>>> issue.parent
{'id': 54321}

But if an issue doesn't have a parent issue, then the parent attribute won't be available. Also at the moment if you call

issue.parent
project.parent

etc., it returns a dict, and not a resource object as it should, this is a bug in the python-redmine and will be fixed in the version. That means that you have to manually fetch the parent issue like that

parent_issue = redmine.issue.get(issue.parent['id'])

If you need to access the children issues from a parent issue you can call

issue.children

which return a ResourceSet object of children issue resources if any

@maxtepkeev maxtepkeev self-assigned this Apr 2, 2014
maxtepkeev added a commit that referenced this issue Apr 2, 2014
@maxtepkeev
Copy link
Owner

The bug with parent resource attribute not being converted to Resource object is fixed in 4d95d93 and will be released to PyPI later today.

@maxtepkeev
Copy link
Owner

v0.8.1 with a fix released to PyPI.

@jeonghanlee
Copy link
Author

Thank you for your explanation.

I selected the wrong Issue which didn't have Parent. After switching to the right one, I could see Parent. And I am happy that my question - accidentally - could contribute to python-redmine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants