Bug 32801

Summary: /checkouts?checked_in=1 errors when itemnumber is null
Product: Koha Reporter: Arthur Suzuki <arthur.suzuki>
Component: REST APIAssignee: Jonathan Druart <jonathan.druart>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P5 - low CC: jonathan.druart, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.02,22.11.08
Bug Depends on: 29290    
Bug Blocks:    
Attachments: Bug 32801: Add tests
Bug 32801: Prevent 500 on /checkouts
Bug 32801: Add tests
Bug 32801: Prevent 500 on /checkouts
Bug 32801: Prevent 500 on /checkouts

Description Arthur Suzuki 2023-02-02 16:26:45 UTC
When trying to fetch checked_in checkouts for a borrower, if the old_issues doesn't have an itemnumber (for example the item was deleted).
It brings a 500 error.

This is a message I got while querying this url : /api/v1/checkouts?patron_id=13662&checked_in=1

<pre>
{"errors":[{"message":"Expected integer - got null.","path":"\/0\/item_id"},{"message":"Expected integer - got null.","path":"\/1\/item_id"},{"message":"Expected integer - got null.","path":"\/9\/item_id"},{"message":"Expected integer - got null.","path":"\/12\/item_id"},{"message":"Expected integer - got null.","path":"\/13\/item_id"},{"message":"Expected integer - got null.","path":"\/14\/item_id"},{"message":"Expected integer - got null.","path":"\/15\/item_id"}],"status":200}
</pre>

Querying with itemnumber not null solves the issue : /api/v1/checkouts?patron_id=13662&checked_in=1&q={"item_id":{"-not_like":"null"}}
Comment 1 Jonathan Druart 2023-07-05 10:28:18 UTC
Created attachment 153044 [details] [review]
Bug 32801: Add tests
Comment 2 Jonathan Druart 2023-07-05 10:28:21 UTC
Created attachment 153045 [details] [review]
Bug 32801: Prevent 500 on /checkouts

If checked_in flag is passed we return the "old checkouts". But if the
item has been deleted we explode with
  "message":"Expected integer - got null.","path":"\/0\/item_id"

The specs should reflect that an item can have been deleted.

Test plan:
Hit the endpoint and confirm the above.
Can be done easily using curl:
  curl -u koha:koha --request GET 'http://localhost:8081/api/v1/checkouts?patron_id=5&checked_in=1' --header "Content-Type: application/json" | jq
Comment 3 Lucas Gass 2023-07-06 22:24:35 UTC
Created attachment 153106 [details] [review]
Bug 32801: Add tests

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 4 Lucas Gass 2023-07-06 22:24:37 UTC
Created attachment 153107 [details] [review]
Bug 32801: Prevent 500 on /checkouts

If checked_in flag is passed we return the "old checkouts". But if the
item has been deleted we explode with
  "message":"Expected integer - got null.","path":"\/0\/item_id"

The specs should reflect that an item can have been deleted.

Test plan:
Hit the endpoint and confirm the above.
Can be done easily using curl:
  curl -u koha:koha --request GET 'http://localhost:8081/api/v1/checkouts?patron_id=5&checked_in=1' --header "Content-Type: application/json" | jq

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 5 Katrin Fischer 2023-07-11 21:50:14 UTC
Created attachment 153340 [details] [review]
Bug 32801: Prevent 500 on /checkouts

If checked_in flag is passed we return the "old checkouts". But if the
item has been deleted we explode with
  "message":"Expected integer - got null.","path":"\/0\/item_id"

The specs should reflect that an item can have been deleted.

Test plan:
Hit the endpoint and confirm the above.
Can be done easily using curl:
  curl -u koha:koha --request GET 'http://localhost:8081/api/v1/checkouts?patron_id=5&checked_in=1' --header "Content-Type: application/json" | jq

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 6 Tomás Cohen Arazi 2023-07-12 17:31:48 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 7 Martin Renvoize 2023-07-18 10:08:19 UTC
Thanks for all the hard work!

Pushed to 23.05.x for the next release
Comment 8 Matt Blenkinsop 2023-07-18 14:14:59 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x