Bug 32801 - /checkouts?checked_in=1 errors when itemnumber is null
Summary: /checkouts?checked_in=1 errors when itemnumber is null
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major (vote)
Assignee: Jonathan Druart
QA Contact:
URL:
Keywords:
Depends on: 29290
Blocks:
  Show dependency treegraph
 
Reported: 2023-02-02 16:26 UTC by Arthur Suzuki
Modified: 2023-12-28 20:47 UTC (History)
2 users (show)

See Also:
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


Attachments
Bug 32801: Add tests (1.23 KB, patch)
2023-07-05 10:28 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32801: Prevent 500 on /checkouts (1.26 KB, patch)
2023-07-05 10:28 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 32801: Add tests (1.28 KB, patch)
2023-07-06 22:24 UTC, Lucas Gass
Details | Diff | Splinter Review
Bug 32801: Prevent 500 on /checkouts (1.31 KB, patch)
2023-07-06 22:24 UTC, Lucas Gass
Details | Diff | Splinter Review
Bug 32801: Prevent 500 on /checkouts (1.37 KB, patch)
2023-07-11 21:50 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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