[Bug 43604] New: commit_file.pl --revert dies: safe_to_delete calls can_edit_items_from on undef
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 Bug ID: 43604 Summary: commit_file.pl --revert dies: safe_to_delete calls can_edit_items_from on undef Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Tools Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Target Milestone: --- This fixes a regression introduced by bug 33070, where Koha::Item->safe_to_delete assumed C4::Context->userenv->{number} always corresponds to a real Koha::Patron. misc/commit_file.pl sets a dummy CLI userenv with borrowernumber 0: C4::Context->set_userenv( 0, 'batch', 0, 'batch', 'batch', 'batch', 'batch' ); Running --revert on a batch calls C4::ImportBatch::BatchRevertItems, which calls Koha::Item->safe_delete on every item created by the batch. safe_delete calls safe_to_delete, which runs: !Koha::Patrons->find( C4::Context->userenv->{number} )->can_edit_items_from( $self->homebranch ) Since there is no patron with borrowernumber 0, Koha::Patrons->find returns undef, and calling ->can_edit_items_from on undef is a fatal error that aborts the whole script. Other call sites touched by bug 33070 already guard against a missing patron (e.g. Koha::UI::Table::Builder::Items->build_table: nomod => $patron ? !$patron->can_edit_items_from(...) : 0), but Koha::Item->safe_to_delete never got the same guard. Test plan: 1. Stage and commit a batch of records so items get created (e.g. via the Manage staged MARC records tool, or misc/commit_file.pl --batch-number NNN). 2. Run: misc/commit_file.pl --batch-number NNN --revert 3. Without this patch, the script dies with: Can't call method "can_edit_items_from" on an undefined value at Koha/Item.pm line 374. 4. Apply the patch. 5. Run: prove t/db_dependent/Koha/Item.t -- all tests pass, including the new regression test. 6. Repeat step 2 -- the batch reverts successfully. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 206586 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=206586&action=edit Bug 43604: Fix Koha::Item->safe_to_delete crash when userenv has no matching patron Koha::Item->safe_to_delete assumed C4::Context->userenv->{number} always corresponds to a real Koha::Patron. misc/commit_file.pl sets a dummy CLI userenv with borrowernumber 0, so running --revert on a batch calls safe_delete/safe_to_delete on each item and dies: Can't call method "can_edit_items_from" on an undefined value at Koha/Item.pm line 374. Guard against Koha::Patrons->find returning undef, matching the pattern already used elsewhere (e.g. Koha::UI::Table::Builder::Items->build_table). Test plan: 1. Run misc/commit_file.pl --batch-number NNN --revert on a committed import batch -- it dies as above. 2. Apply this patch. 3. prove t/db_dependent/Koha/Item.t -- all tests pass. 4. Repeat step 1 -- the batch reverts successfully. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |33070 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33070 [Bug 33070] Get rid of Koha::Patron->can_edit_item and use can_edit_item_from instead -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |major -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |26.11 Patch complexity|--- |Trivial patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |katrin.fischer@bsz-bw.de -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org