python-redmine icon indicating copy to clipboard operation
python-redmine copied to clipboard

What are all filter operations for issues

Open necrolyte2 opened this issue 10 years ago • 10 comments

I found this in the documentation for filtering issues

issues = redmine.issue.filter(
    project_id='vacation',
    subproject_id='!*', 
    created_on='><2012-03-01|2012-03-07',
    sort='category:desc
)

I see that you have ><fromdate|todate Is there a listing somewhere of all of the available operators

For my specific case I want to do an in or or operation such as

redmine.issue.filter(
    project_id='vacation',
    author_id='in5,6', # Not sure what to put here to do an IN or OR operation
)

necrolyte2 avatar Oct 23 '14 19:10 necrolyte2

This information is from official Redmine REST API docs. You can see the available combinations at the link I provided, but I believe that this kind of query will only work with timestamp fields, so I'm 99% sure that this won't work for your exact case. Also I've just tried to find all issues from a project with more than one author via the usual Redmine GUI and I wasn't able to do that, because when you apply the author filter for one person, you can't add second author filter for another person, so it just isn't possible at all. You have to get all issues from a project and then filter them in cycle.

Speaking about this filter operations - this is not a magic done by Python-Redmine, this filter operations are provided by the Redmine itself and Python-Redmine just sends this operations to Redmine and receives the response.

maxtepkeev avatar Oct 24 '14 06:10 maxtepkeev

I guess author_id is a bad example. This really isn't python-redmine's fault as much as it is Redmine's documentation, but there doesn't seem to be any place that lists the operators that you can use for the different field types.

Say if you have a Custom Field that is a MultipleList type. From Redmine's interface you can do an in operation, but I'm not sure how to do it through the api

necrolyte2 avatar Oct 24 '14 19:10 necrolyte2

Yeah, I understand the problem.

I also wasn't able to find any docs that lists all the available operators, so I looked at Redmine's source code and I believe that it should be what we're looking for, though I didn't test it and I'm not sure if it will work.

Also I don't have an answer right now to your question about multiple custom fields.

I believe the only thing we can do is to look through the entire Redmine's source code and to find all this operators, then test them and see if they work or not. This is a big amount of work, so I can't do that right now, but I will do a little bit later.

This issue will remain open until we won't find answers to all this questions.

maxtepkeev avatar Oct 28 '14 07:10 maxtepkeev

I figured I'd chime in quickly and mention that I had problems filtering issues against a datetime. Date worked fine, but datetime would not. I found that the ability to filter against a datetime was added in Redmine 2.5, and I was using 2.4.

http://www.redmine.org/issues/8842

Once I upgraded, I could use a filter like: redmine.issue.filter(updated_on='>=%s' % last_checked.strftime('%Y-%m-%dT%H:%M:%SZ'))

Cheers!

jesselang avatar Oct 29 '14 16:10 jesselang

Redmine 2.6 references the "fixed_version" in two places which might be worth investigating

== versions_controller.rb

47         @issues_by_version = {}
 48         if @selected_tracker_ids.any? && @versions.any?
 49           issues = Issue.visible.
 50             includes(:project, :tracker).
 51             preload(:status, :priority, :fixed_version).
 52             where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
 53             order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
 54           @issues_by_version = issues.group_by(&:fixed_version)

== issue_query.rb

197     if versions.any?
198       add_available_filter "fixed_version_id",
199         :type => :list_optional,
200         :values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] }
201     end
...
388   # Returns the versions
389   # Valid options are :conditions
390   def versions(options={})
391     Version.visible.
392       where(project_statement).
393       where(options[:conditions]).
394       includes(:project).
395       all

indera avatar Sep 03 '15 15:09 indera

I can confirm that the API supports filtering the issues by the "fixed_version_id=your_sprint_id"

@see https://github.com/ctsit/redman/blob/master/fabfile.py#L350

indera avatar Sep 09 '15 20:09 indera

I did some testing with the fixed_version parameter for selecting all issues related to a particular version within a project Based on a StackOverflow answer[1]. It seems to work properly only when you also add the project_id in the url, something the python-redmine issue.filter() function currently does not do. I also could not find this case documentation in the redmine REST API documentation. However, it does work luckily. The author of the answer uses the following:

GET /projects/[project id]/issues.json?set_filter=1&fixed_version_id=[fixed version id]

[1]http://stackoverflow.com/questions/19906773/using-redmine-rest-api-to-access-issues-with-criteria

Maybe nice to add this in a next version of python-redmine?

benvdh avatar Aug 12 '16 00:08 benvdh

Ok, just found the documentation @necrolyte2 was looking for:

http://www.freelancingdigest.com/articles/redmine-query-reference/

@maxtepkeev: would it be possible to somehow integrate the above in python-redmine?

benvdh avatar Aug 12 '16 11:08 benvdh

@benvdh

Regarding the https://github.com/maxtepkeev/python-redmine/issues/57#issuecomment-239331751, thanks for this information, the problem is that if we use the /projects/[project id]/issues.json URL instead of just issues.json in issue.filter() we make the project_id argument required which is not what we want in most cases, I have to think how to implement this properly.

Regarding the https://github.com/maxtepkeev/python-redmine/issues/57#issuecomment-239425699 - cool, thanks for this, I definitely will add this into new documentation which will be available together with python-redmine v2.0 that should be ready approximately by the end of October.

maxtepkeev avatar Aug 12 '16 16:08 maxtepkeev

Not sure whether this the most elegant solution, but might a filter_by_project() method be an option ?

Personally, I implemented by creating a custom_resource class, and changed the url there...

benvdh avatar Aug 25 '16 14:08 benvdh