Bug 33885 - Get HTTP 500 when retrieving orders created by a non-existent (deleted) user
Summary: Get HTTP 500 when retrieving orders created by a non-existent (deleted) user
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: Main
Hardware: All All
: P5 - low critical (vote)
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on: 8179
Blocks:
  Show dependency treegraph
 
Reported: 2023-06-02 07:58 UTC by Slava Shishkin
Modified: 2023-07-10 13:54 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes an issue that prevents the receiving of items where the user who created the order has been deleted. When clicking on 'Receive' for an item, this error was displayed: "Something went wrong when loading the table. 500: Internal Server Error."
Version(s) released in:
23.11.00,23.05.01


Attachments
Bug 33885: Make Koha::Acq::Order->creator return undef if no creator (1.76 KB, patch)
2023-06-07 09:08 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33885: Prevent JS crash if creator does no longer exist (1.77 KB, patch)
2023-06-07 09:08 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33885: Make Koha::Acq::Order->creator return undef if no creator (1.80 KB, patch)
2023-06-07 21:43 UTC, David Nind
Details | Diff | Splinter Review
Bug 33885: Prevent JS crash if creator does no longer exist (1.81 KB, patch)
2023-06-07 21:43 UTC, David Nind
Details | Diff | Splinter Review
Bug 33885: Make Koha::Acq::Order->creator return undef if no creator (1.86 KB, patch)
2023-06-16 13:18 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 33885: Prevent JS crash if creator does no longer exist (1.87 KB, patch)
2023-06-16 13:18 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Slava Shishkin 2023-06-02 07:58:35 UTC
Problem description:
Occurs for orders where 'created_by' is NULL with the message in log:
  DBIC result _type isn't of the _type Borrower at /usr/share/koha/lib/Koha/Objects.pm line 463.

This did not occur before in version 22.11 because there was no modal and the logic was different. Generally, according to the design, it is assumed that 'created_by' can be NULL, for example, due to a constraint that cleans it when the borrower record is deleted from the database.


Steps to reproduce:

1. Create a superuser.
2. Add an order to the cart as a new user.
3. Delete the new user from the system.
4. Go to the orders section and select an order created by the non-existent user.
5. Click the "Get Order" button.

Expected behavior:
When attempting to retrieve an order created by a non-existent user, a confirmation pop-up window should appear for order retrieval.

Actual behavior:
Clicking the "Receive" button results in a JS alert with 'error 500 / The system is unable to process the request and returns an internal server error' message.
Comment 1 Jonathan Druart 2023-06-07 09:08:31 UTC
Created attachment 152080 [details] [review]
Bug 33885: Make Koha::Acq::Order->creator return undef if no creator

If the account of the creator of an order has been deleted we should
return undef here, instead of crashing with
GET /api/v1/acquisitions/orders: unhandled exception (Mojo::Exception)<<DBIC result _type  isn't of the _type Borrower at /kohadevbox/koha/Koha/Objects.pm line 445.
Comment 2 Jonathan Druart 2023-06-07 09:08:34 UTC
Created attachment 152081 [details] [review]
Bug 33885: Prevent JS crash if creator does no longer exist

JS error in the console was
  Uncaught TypeError: row.creator is null
Comment 3 David Nind 2023-06-07 21:43:52 UTC
Created attachment 152137 [details] [review]
Bug 33885: Make Koha::Acq::Order->creator return undef if no creator

If the account of the creator of an order has been deleted we should
return undef here, instead of crashing with
GET /api/v1/acquisitions/orders: unhandled exception (Mojo::Exception)<<DBIC result _type  isn't of the _type Borrower at /kohadevbox/koha/Koha/Objects.pm line 445.

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2023-06-07 21:43:54 UTC
Created attachment 152138 [details] [review]
Bug 33885: Prevent JS crash if creator does no longer exist

JS error in the console was
  Uncaught TypeError: row.creator is null

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Nind 2023-06-07 22:01:11 UTC
Testing notes (using KTD):

1. Edited user Henry Acevedo: set permissions so that Henry is a superlibrarian, change username (to Henry) and password (Policy10) so that you can log is as Henry.

2. Login as Henry and:
   - create a basket
   - add an item to the basket
   - close the basket

3. Login as user koha.

4. Delete the Henry Acevedo user.

5. Go to receive the order - when selecting 'Receive' in the table that lists the items ordered, you get this pop up error:
"Something went wrong when loading the table.
500: Internal Server Error."

6. Apply the patch, refresh the page listing the items to receive, click 'Receive' ==> the receive window is now displayed without any errors.

Reference:
- IRC chat on how to replicate the issue: https://irc.koha-community.org/koha/2023-06-07#i_2490125
Comment 6 Tomás Cohen Arazi 2023-06-16 13:18:56 UTC
Created attachment 152413 [details] [review]
Bug 33885: Make Koha::Acq::Order->creator return undef if no creator

If the account of the creator of an order has been deleted we should
return undef here, instead of crashing with
GET /api/v1/acquisitions/orders: unhandled exception (Mojo::Exception)<<DBIC result _type  isn't of the _type Borrower at /kohadevbox/koha/Koha/Objects.pm line 445.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 7 Tomás Cohen Arazi 2023-06-16 13:18:58 UTC
Created attachment 152414 [details] [review]
Bug 33885: Prevent JS crash if creator does no longer exist

JS error in the console was
  Uncaught TypeError: row.creator is null

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 8 Tomás Cohen Arazi 2023-06-16 13:55:54 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 9 Fridolin Somers 2023-06-26 12:43:31 UTC
Pushed to 23.05.x for 23.05.01
Comment 10 Pedro Amorim 2023-07-10 13:54:13 UTC
Missing dependencies for 22.11.x. Not pushing.