Bug 41510 - Fallback on bookable itemtype can break if item has no itemtype
Summary: Fallback on bookable itemtype can break if item has no itemtype
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-02 09:21 UTC by Paul Derscheid
Modified: 2026-01-03 02:48 UTC (History)
2 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 41510: Add test for effective_bookable with missing itemtype (2.10 KB, patch)
2026-01-02 10:23 UTC, Paul Derscheid
Details | Diff | Splinter Review
Bug 41510: Handle undefined itemtype in item->effective_bookable (964 bytes, patch)
2026-01-02 10:23 UTC, Paul Derscheid
Details | Diff | Splinter Review
Bug 41510: Add test for effective_bookable with missing itemtype (2.15 KB, patch)
2026-01-03 02:48 UTC, David Nind
Details | Diff | Splinter Review
Bug 41510: Handle undefined itemtype in item->effective_bookable (1011 bytes, patch)
2026-01-03 02:48 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Derscheid 2026-01-02 09:21:36 UTC
I think this is a rare case, but we need to guard against it.
Comment 1 Paul Derscheid 2026-01-02 10:23:54 UTC
Created attachment 190820 [details] [review]
Bug 41510: Add test for effective_bookable with missing itemtype

- Add test case for the scenario where an item has no itemtype
  because both items.itype and biblioitems.itemtype are NULL
- Note: We must set biblioitems.itemtype to NULL before creating the
  item because Koha::Item->store() automatically populates itype from
  biblioitems.itemtype when itype is not set

Test plan:
- Apply this patch only
- Run: prove t/db_dependent/Koha/Item.t :: effective_bookable
- Verify test 6 FAILS with "Can't call method 'bookable' on an
  undefined value"
- Apply the follow-up patch
- Run the test again
- Verify all tests PASS
Comment 2 Paul Derscheid 2026-01-02 10:23:56 UTC
Created attachment 190821 [details] [review]
Bug 41510: Handle undefined itemtype in item->effective_bookable

- Guard against undefined itemtype before calling ->bookable on it
- Return 0 (not bookable) when no itemtype is found and item-level
  bookable is not defined
Comment 3 David Nind 2026-01-03 02:48:04 UTC
Created attachment 190854 [details] [review]
Bug 41510: Add test for effective_bookable with missing itemtype

- Add test case for the scenario where an item has no itemtype
  because both items.itype and biblioitems.itemtype are NULL
- Note: We must set biblioitems.itemtype to NULL before creating the
  item because Koha::Item->store() automatically populates itype from
  biblioitems.itemtype when itype is not set

Test plan:
- Apply this patch only
- Run: prove t/db_dependent/Koha/Item.t :: effective_bookable
- Verify test 6 FAILS with "Can't call method 'bookable' on an
  undefined value"
- Apply the follow-up patch
- Run the test again
- Verify all tests PASS

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2026-01-03 02:48:07 UTC
Created attachment 190855 [details] [review]
Bug 41510: Handle undefined itemtype in item->effective_bookable

- Guard against undefined itemtype before calling ->bookable on it
- Return 0 (not bookable) when no itemtype is found and item-level
  bookable is not defined

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