Bug 31873

Summary: Can't call method "safe_delete" on an undefined value at cataloguing/additem.pl
Product: Koha Reporter: Marcel de Rooy <m.de.rooy>
Component: Architecture, internals, and plumbingAssignee: Marcel de Rooy <m.de.rooy>
Status: CLOSED FIXED QA Contact: Martin Renvoize <martin.renvoize>
Severity: normal    
Priority: P5 - low CC: arthur.suzuki, lucas, martin.renvoize, wainuiwitikapark
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.11.00, 22.05.09
Bug Depends on: 29746    
Bug Blocks:    
Attachments: Bug 31873: Check ->find before calling ->safe_delete
Bug 31873: Check ->find before calling ->safe_delete
Bug 31873: Check ->find before calling ->safe_delete

Description Marcel de Rooy 2022-10-19 13:37:07 UTC
Line 379 in 21.11.
Line 415 in master now.

    my $item = Koha::Items->find($itemnumber);
    my $error = $item->safe_delete;

No check whatsoever.
Comment 1 Marcel de Rooy 2022-10-19 13:52:23 UTC
Created attachment 142155 [details] [review]
Bug 31873: Check ->find before calling ->safe_delete

When there is no item, you cannot safely delete it :)

Resolve this warning:
  Can't call method "safe_delete" on an undefined value at /usr/share/koha/cataloguing/additem.pl line 379
(Line numbers may vary across versions.)

Test plan:
Open item editor.
Add a new item.
Add another tab with same form. Delete new item.
Go back to former tab. Try to delete again.
You should see an alert now on top of the form.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 2 Marcel de Rooy 2022-10-19 14:08:18 UTC
NOTE: The log file did not tell me the real reproduction scenario but the test plan should be enough to catch the point.
Comment 3 Marcel de Rooy 2022-10-19 14:13:28 UTC
Note that this cannot be backported without change in 21.11 due to Boolean.pm stuff. If needed, I have a patch.
Comment 4 David Nind 2022-10-19 19:34:55 UTC
Created attachment 142206 [details] [review]
Bug 31873: Check ->find before calling ->safe_delete

When there is no item, you cannot safely delete it :)

Resolve this warning:
  Can't call method "safe_delete" on an undefined value at /usr/share/koha/cataloguing/additem.pl line 379
(Line numbers may vary across versions.)

Test plan:
Open item editor.
Add a new item.
Add another tab with same form. Delete new item.
Go back to former tab. Try to delete again.
You should see an alert now on top of the form.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: David Nind <david@davidnind.com>

https://bugs.koha-community.org/show_bug.cgi?id=31783
Comment 5 Martin Renvoize 2022-11-02 16:53:11 UTC
Created attachment 143012 [details] [review]
Bug 31873: Check ->find before calling ->safe_delete

When there is no item, you cannot safely delete it :)

Resolve this warning:
  Can't call method "safe_delete" on an undefined value at /usr/share/koha/cataloguing/additem.pl line 379
(Line numbers may vary across versions.)

Test plan:
Open item editor.
Add a new item.
Add another tab with same form. Delete new item.
Go back to former tab. Try to delete again.
You should see an alert now on top of the form.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize 2022-11-02 16:53:43 UTC
Works as described, code is clean.

Passing QA
Comment 7 Tomás Cohen Arazi 2022-11-03 14:32:23 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 8 Lucas Gass 2023-01-17 15:41:33 UTC
Backported to 22.05.x for upcoming 22.05.09
Comment 9 Arthur Suzuki 2023-01-26 09:03:18 UTC
pushed to 21.11.x for 21.11.16
Comment 10 Arthur Suzuki 2023-01-27 11:04:35 UTC
Reverted on 21.11.x branch, missing Koha::Result::Boolean dependency.
Comment 11 wainuiwitikapark 2023-03-15 01:26:03 UTC
Not backported to 21.05.x