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

Time Entry all()/filter() returns a fixed 25 items #37

Closed
Augustin82 opened this Issue Jul 30, 2014 · 4 comments

Comments

2 participants
@Augustin82

Augustin82 commented Jul 30, 2014

Hi!

I have been experimenting a surprising behaviour, querying time entries.

It seems that the request always returns a maximum of 25 items, before taking limit/offset into account.

I get 43 time entries when I use the REST API:

https://MY_SERVER/time_entries.xml?from=2014-07-22

Let me clarify that with examples:

>>> time_entries = redmine.time_entry.filter(from_date="2014-07-22")
>>> len(time_entries)
25

>>> time_entries = redmine.time_entry.filter(from_date="2014-07-22", limit=24)
>>> len(time_entries)
24

>>> time_entries = redmine.time_entry.filter(from_date="2014-07-22", limit=25)
>>> len(time_entries)
25

>>> time_entries = redmine.time_entry.filter(from_date="2014-07-22", limit=26)
>>> len(time_entries)
25

>>> time_entries = redmine.time_entry.filter(from_date="2014-07-22", offset=24)
>>> len(time_entries)
1

>>> time_entries = redmine.time_entry.filter(from_date="2014-07-22", offset=25)
>>> len(time_entries)
0

This behaviour does not occur with, say, issues. I am using version 0.8.2 installed via pip.

Any idea what may be happening here? Am I doing something wrong?

Many thanks!

@maxtepkeev maxtepkeev added the question label Jul 30, 2014

@maxtepkeev maxtepkeev self-assigned this Jul 30, 2014

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Jul 30, 2014

Hi Augustin!

I can't reproduce this problem here. It works for me as it should, can you tell me a little bit more about your environment i.e. Redmine and Python version.

@Augustin82

This comment has been minimized.

Augustin82 commented Jul 30, 2014

Hi Max,

thank you for answering.

I am running Python 2.7.6 and we run ChiliProject (3.2.1.221a2e73c), not a vanilla Redmine. Apologies for not stating this right away, I should have. I didn't think it would be a factor, since the REST API works like it should, returning the right number of items.

Do you have any idea what could cause this discrepancy?

Cheers.

@maxtepkeev

This comment has been minimized.

Owner

maxtepkeev commented Jul 30, 2014

I think I found the problem and it's related with this ChiliProject fork of Redmine. Below is the detailed explanation of the problem.

ChiliProject's REST API for time entries doesn't support limit and offset for some reason, you can test that by yourself, e.g. https://YOUR_SERVER/time_entries.json?limit=1 won't work. On the other hand if you try this on native Redmine it will work.

Python-Redmine tries it's best to mimic limit/offset if it's not supported by the Redmine resource itself. So it's also tries to mimic it for the ChiliProject's time entries. But why you get only 25 resources ? Read below.

In ChiliProject you can use per_page and page GET parameters to control what time entries you want to get, by default it's using per_page=25 & page=1, this is why you always get 25 entries.

So what can you do ? You can use python-redmine with parameters per_page and page to get time entries and then make additional request for the next page and check if there are more entries and then make another request if there more etc., e.g:

    time_entries = redmine.time_entry.filter(from_date="2014-07-22", per_page=100, page=2)

per_page only supports values of 25, 50 and 100. So you can't do per_page=1 or 10, if you need this you can add limit parameter and python-redmine will limit results manually for you, e.g.:

    time_entries = redmine.time_entry.filter(from_date="2014-07-22", per_page=100, page=2, limit=10)

Also I highly recommend you to fill a feature request for the ChiliProject to add support for limit/offset on it's own level to be more compatible with Redmine and also to make requests to API more efficient.

Hope that helps. If you still have questions feel free to ask, if not, feel free to close this issue.

@Augustin82

This comment has been minimized.

Augustin82 commented Jul 30, 2014

Wow, I'm really impressed! You've juste saved me more hours of frustration, by debugging something you are not responsible for.
Thank you very much for your great explanation and for the solution. I'm going to post another issue regarding time entries but this one is solved.

@Augustin82 Augustin82 closed this Jul 30, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment