Bug 31873 - Can't call method "safe_delete" on an undefined value at cataloguing/additem.pl
Summary: Can't call method "safe_delete" on an undefined value at cataloguing/additem.pl
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Marcel de Rooy
QA Contact: Martin Renvoize
URL:
Keywords:
Depends on: 29746
Blocks:
  Show dependency treegraph
 
Reported: 2022-10-19 13:37 UTC by Marcel de Rooy
Modified: 2023-12-28 20:42 UTC (History)
4 users (show)

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


Attachments
Bug 31873: Check ->find before calling ->safe_delete (2.95 KB, patch)
2022-10-19 13:52 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 31873: Check ->find before calling ->safe_delete (3.01 KB, patch)
2022-10-19 19:34 UTC, David Nind
Details | Diff | Splinter Review
Bug 31873: Check ->find before calling ->safe_delete (3.02 KB, patch)
2022-11-02 16:53 UTC, Martin Renvoize
Details | Diff | Splinter Review

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