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

filter custom field #13

Closed
ds485 opened this issue Mar 6, 2014 · 2 comments
Closed

filter custom field #13

ds485 opened this issue Mar 6, 2014 · 2 comments
Assignees
Labels

Comments

@ds485
Copy link

ds485 commented Mar 6, 2014

Hi,
if I filter issues by a custom field I am getting all issues returned if the project dosen't use this custom field

example:
if I got two projects, p1 and p2 with each 10 issues and only p2 is using my custom field cf which is always empty (with id 1)

for project in redmine.project.all():
    print project.name, len(redmine.issue.filter(project_id=project.id, subproject_id='!*', cf_1="random"))

the result is:

p1 10
p2 0

I would expect that both results are 0 or an exception for p1

@maxtepkeev
Copy link
Owner

Hi,

Yes, you are right. Unfortunately we can do nothing about it because this is how the custom fields filtering works on the Redmine side and Python Redmine is just the interface for the Redmine API.

So one thing that you can do is to fill a bug report on the Redmine forum and probably they will fix it some day. Until they fix this behaviour you can check the custom field flag to make it work for all projects and not just the specific one(s), this way issue filtering will work as you expect.

Probably another thing you can do is something like

for project in redmine.project.all():
    issues = redmine.issue.filter(project_id=project.id, subproject_id='!*', cf_1="random")
    issue_count = len(issues)

    if issue_count > 0 and issues[0].custom_fields.get(1) is not None:
        print 'Project {0} has {1} issues with custom field with an id of 1'.format(project.name, issue_count)
    else:
        print 'Project {0} has no issues with custom field with an id of 1'.format(project.name)

Of course this is a dirty workaround around the Redmine API behaviour but it should work. Also keep in mind that I haven't check this code but again, it should work.

@maxtepkeev maxtepkeev self-assigned this Mar 7, 2014
@maxtepkeev
Copy link
Owner

Sorry there was a logical error in my code. I updated my previous comment with the correct version. Though it's not the complete solution to your problem, e.g. it doesn't check for a specific value for a custom field, but you should get the general idea about how you can accomplish what you need.

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