[Bug 42935] New: Koha::Item->_status croaks when an item references a non-existent item type
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42935 Bug ID: 42935 Summary: Koha::Item->_status croaks when an item references a non-existent item type Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: paul.derscheid@lmscloud.de QA Contact: testopia@bugs.koha-community.org Target Milestone: --- Koha::Item->_status calls $self->item_type->notforloan. item_type resolves via Koha::ItemTypes->find( $self->effective_itemtype ), which returns undef when the item's effective item type is set to a value that has no matching row in the itemtypes table. _status then croaks with: Can't call method "notforloan" on an undefined value at Koha/Item.pm This is the non-NULL-but-invalid case (an orphaned itype value, not an empty one). Impact: a 500 on GET /api/v1/biblios/{biblio_id}/items (the _status embed), so the catalogue detail items table fails to load for the whole record if any one of its items references a non-existent item type. The state is not reachable through normal editing; it arises out of band, e.g. deleting an item type still referenced by items, or an SQL import/migration - which Koha already flags as a data inconsistency (Koha::Database::DataInconsistency::invalid_item_type). To reproduce (item-level itypes): 1. UPDATE items SET itype = 'NOPE' WHERE itemnumber = <X>; ('NOPE' being any value absent from the itemtypes table) 2. Open that record's detail page in the staff interface. => the items table fails to load; the plack log shows the croak above. Expected: the item row loads; a non-existent item type must not be treated as a croak (and should not count as not-for-loan). -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42935 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |paul.derscheid@lmscloud.de |ity.org | See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=40034 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42935 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Trivial patch Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42935 --- Comment #1 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 201162 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201162&action=edit Bug 42935: _status should not croak when an item's itemtype is missing Koha::Item::_status does $self->item_type->notforloan, but item_type (Koha::ItemTypes->find( effective_itemtype )) can return undef. With item-level_itypes enabled, an items.itype holding a non-null code that is absent from the itemtypes table resolves to that code via effective_itemtype, and Koha::ItemTypes->find() then returns undef. items.itype has no enforced FK to itemtypes, so this is reachable with out-of-band data (SQL import/migration). A NULL items.itype does not trigger this: effective_itemtype falls back to the biblio-level itemtype. The problem is specifically a non-null code with no matching itemtype. Like the home_library/holding_library case, this surfaces as a 500 on GET /api/v1/biblios/{biblio_id}/items (the catalogue detail items table). Cache the item_type lookup (per the existing TODO) and guard the itemtype-level notforloan check, mirroring the existing guard in effective_not_for_loan_status, so a missing itemtype no longer dies. Test plan: 1. prove t/db_dependent/Koha/Item.t => the new subtest '_status() with a missing item type' fails with 'Can't call method "notforloan" on an undefined value' 2. Apply this patch 3. prove t/db_dependent/Koha/Item.t => green To reproduce the original 500 in the UI instead (item-level_itypes on): 1. UPDATE items SET itype = 'NOPE' WHERE itemnumber = <X>; -- not in itemtypes 2. Open that record's detail page; the holdings table fails to load and the plack log shows the croak above 3. Apply this patch and koha-plack --restart kohadev 4. Reload; the holdings table loads -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42935 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |RESOLVED Resolution|--- |INVALID -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org