Bug 25570

Summary: Listing requests should be paginated by default
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: REST APIAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: CLOSED FIXED QA Contact: Martin Renvoize (ashimema) <martin.renvoize>
Severity: normal    
Priority: P5 - low CC: aleisha, jonathan.druart, lucas, martin.renvoize, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.11.00, 20.05.02, 19.11.08, 19.05.14
Circulation function:
Bug Depends on: 19410, 24229    
Bug Blocks: 26143    
Attachments: Bug 25570: Regression tests
Bug 25570: Paginate results by default in objects->search
Bug 25570: (follow-up) Fix tests
Bug 25570: Regression tests
Bug 25570: Paginate results by default in objects->search
Bug 25570: (follow-up) Fix tests
Bug 25570: Regression tests
Bug 25570: Paginate results by default in objects->search
Bug 25570: (follow-up) Fix tests
Bug 25570: Allow "all", -1

Description Tomás Cohen Arazi (tcohen) 2020-05-21 14:32:48 UTC
They were supposed to be paginated by default, but we lost that (or maybe just the idea) at some point.

If pagination information is not passed, it should default to page 1, and page size to  RESTdefaultPageSize.
Comment 1 Tomás Cohen Arazi (tcohen) 2020-05-21 21:32:24 UTC
Created attachment 105229 [details] [review]
Bug 25570: Regression tests

This tests verify that the default behaviour is to paginate the results.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: $c->objects->search doesn't paginate results by default
Comment 2 Tomás Cohen Arazi (tcohen) 2020-05-21 21:32:29 UTC
Created attachment 105230 [details] [review]
Bug 25570: Paginate results by default in objects->search

This patch makes the helper paginate the resultsif no pagination
parameters are passed.

Page number defaults to 1, and the page size to the RESTdefaultPageSize
syspref value.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: Pagination is not enforced by default
3. Apply this patch
4. Repeat 2
=> SUCCESS: Results are paginated
5. Sign off :-D
Comment 3 Tomás Cohen Arazi (tcohen) 2020-05-21 21:32:34 UTC
Created attachment 105231 [details] [review]
Bug 25570: (follow-up) Fix tests

This patch fixes the libraries tests, that expected the old behaviour

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/libraries.t
=> FAIL: Tests fail
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass!
4. Sign off :-D
Comment 4 Jonathan Druart 2020-05-22 07:59:20 UTC
Created attachment 105248 [details] [review]
Bug 25570: Regression tests

This tests verify that the default behaviour is to paginate the results.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: $c->objects->search doesn't paginate results by default

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 5 Jonathan Druart 2020-05-22 07:59:23 UTC
Created attachment 105249 [details] [review]
Bug 25570: Paginate results by default in objects->search

This patch makes the helper paginate the resultsif no pagination
parameters are passed.

Page number defaults to 1, and the page size to the RESTdefaultPageSize
syspref value.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: Pagination is not enforced by default
3. Apply this patch
4. Repeat 2
=> SUCCESS: Results are paginated
5. Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 6 Jonathan Druart 2020-05-22 07:59:26 UTC
Created attachment 105250 [details] [review]
Bug 25570: (follow-up) Fix tests

This patch fixes the libraries tests, that expected the old behaviour

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/libraries.t
=> FAIL: Tests fail
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass!
4. Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 7 Martin Renvoize (ashimema) 2020-05-22 08:30:17 UTC
I think we should target 20.05.01 for this one.
Comment 8 Martin Renvoize (ashimema) 2020-06-19 11:45:56 UTC
Created attachment 106070 [details] [review]
Bug 25570: Regression tests

This tests verify that the default behaviour is to paginate the results.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: $c->objects->search doesn't paginate results by default

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 9 Martin Renvoize (ashimema) 2020-06-19 11:45:59 UTC
Created attachment 106071 [details] [review]
Bug 25570: Paginate results by default in objects->search

This patch makes the helper paginate the resultsif no pagination
parameters are passed.

Page number defaults to 1, and the page size to the RESTdefaultPageSize
syspref value.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: Pagination is not enforced by default
3. Apply this patch
4. Repeat 2
=> SUCCESS: Results are paginated
5. Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 10 Martin Renvoize (ashimema) 2020-06-19 11:46:02 UTC
Created attachment 106072 [details] [review]
Bug 25570: (follow-up) Fix tests

This patch fixes the libraries tests, that expected the old behaviour

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/libraries.t
=> FAIL: Tests fail
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass!
4. Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 11 Martin Renvoize (ashimema) 2020-06-19 11:46:26 UTC
Works as expected, tests pass, qa script passes..

Passing QA
Comment 12 Jonathan Druart 2020-06-24 13:32:52 UTC
Pushed to master for 20.11, thanks to everybody involved!
Comment 13 Jonathan Druart 2020-06-25 08:09:35 UTC
Tomas, if "all" is selected we get an error:

[2020-06-25 07:58:51.08130] [2024] [debug] Routing to controller "Koha::REST::V1::Libraries" and action "list"                                                                                                     No method pager found for Koha::Libraries Fewer than one entry per page! at /usr/share/perl5/DBIx/Class/ResultSet.pm line 2542.                                                                                    
 at /kohadevbox/koha/Koha/REST/Plugin/Objects.pm line 127.                                                                                                                                                         [2020-06-25 07:58:51.10649] [2024] [debug] 500 Internal Server Error (0.053242s, 18.782/s)    

Caught by Jenkins on Master_D9 run #1375, t/db_dependent/selenium/administration_tasks.t
Comment 14 Jonathan Druart 2020-06-25 08:10:17 UTC
Created attachment 106277 [details] [review]
Bug 25570: Allow "all", -1
Comment 15 Jonathan Druart 2020-06-25 08:14:38 UTC
Is this patch correct? It fixes the problem.

I did not manage to find a good place for the tests. Should it be in t/Koha/REST/Plugin/Pagination.t, t/db_dependent/Koha/REST/Plugin/Objects.t or both?
Comment 16 Lucas Gass (lukeg) 2020-07-10 15:48:06 UTC
backported to 20.05.x for 20.05.02
Comment 17 Aleisha Amohia 2020-07-12 22:49:31 UTC
backported to 19.11.x for 19.11.08
Comment 18 Victor Grousset/tuxayo 2020-07-23 22:13:53 UTC
Backported to 19.05.x branch for 19.05.14
Comment 19 Tomás Cohen Arazi (tcohen) 2021-01-08 13:43:36 UTC
(In reply to Jonathan Druart from comment #13)
> Tomas, if "all" is selected we get an error:
> 
> [2020-06-25 07:58:51.08130] [2024] [debug] Routing to controller
> "Koha::REST::V1::Libraries" and action "list"                               
> No method pager found for Koha::Libraries Fewer than one entry per page! at
> /usr/share/perl5/DBIx/Class/ResultSet.pm line 2542.                         
> 
>  at /kohadevbox/koha/Koha/REST/Plugin/Objects.pm line 127.                  
> [2020-06-25 07:58:51.10649] [2024] [debug] 500 Internal Server Error
> (0.053242s, 18.782/s)    
> 
> Caught by Jenkins on Master_D9 run #1375,
> t/db_dependent/selenium/administration_tasks.t

This was caught in the wild, and I solved it on bug 26143, before noticing this comment. Sorry dude.