Bug 35167 - GET /items* broken if notforloan == 0 and itemtype.notforloan == NULL
Summary: GET /items* broken if notforloan == 0 and itemtype.notforloan == NULL
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major
Assignee: Tomás Cohen Arazi (tcohen)
QA Contact: Marcel de Rooy
URL:
Keywords: rel_22_11_candidate, rel_23_05_candidate, rel_23_11_candidate
Depends on: 31128
Blocks:
  Show dependency treegraph
 
Reported: 2023-10-26 14:30 UTC by Tomás Cohen Arazi (tcohen)
Modified: 2024-07-04 20:40 UTC (History)
6 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:
23.11.00,23.05.05,22.11.12
Circulation function:


Attachments
Bug 35167: Regression tests (1.55 KB, patch)
2023-10-26 18:59 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 35167: Make 'effective_not_for_loan_status' fallback to 0 if itype has it undef (1.31 KB, patch)
2023-10-26 18:59 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 35167: Regression tests (1.60 KB, patch)
2023-10-26 20:20 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 35167: Make 'effective_not_for_loan_status' fallback to 0 if itype has it undef (1.36 KB, patch)
2023-10-26 20:20 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 35167: Regression tests (1.70 KB, patch)
2023-10-27 06:15 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 35167: Make 'effective_not_for_loan_status' fallback to 0 if itype has it undef (1.46 KB, patch)
2023-10-27 06:15 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi (tcohen) 2023-10-26 14:30:09 UTC
The Koha::Item->to_api method has this (modded for readability):

$overrides->{effective_not_for_loan_status} =
         $self->notforloan 
             ? $self->notforloan
             : $self->itemtype->notforloan;

This is weird, because on the table definition, that column is defined as NOT NULL:

  `notforloan` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'authorized value defining why this item is not for loan (MARC21 952$7)',

so, if the item has a value of '0', then it will look for the itemtype's default `notforloan` value, which can be (and most of the time is) NULL!

I will provide a patch checking 'defined $self->notforloan' but it feels like adding `effective_not_for_loan_status` was a mistake.
Comment 1 Tomás Cohen Arazi (tcohen) 2023-10-26 14:45:34 UTC
I understood now how it works on the UI and will provide a fix :-D.

Thanks Nick and Kyle.
Comment 2 Tomás Cohen Arazi (tcohen) 2023-10-26 18:59:36 UTC
Created attachment 157948 [details] [review]
Bug 35167: Regression tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 3 Tomás Cohen Arazi (tcohen) 2023-10-26 18:59:39 UTC
Created attachment 157949 [details] [review]
Bug 35167: Make 'effective_not_for_loan_status' fallback to 0 if itype has it undef

This patch makes the effective not for loan status be set the item value
if not defined at itype level.

To test:
1. Apply the regressions tests patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/items.t
=> FAIL: Tests fail!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 4 Lucas Gass (lukeg) 2023-10-26 20:20:55 UTC
Created attachment 157954 [details] [review]
Bug 35167: Regression tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 5 Lucas Gass (lukeg) 2023-10-26 20:20:57 UTC
Created attachment 157955 [details] [review]
Bug 35167: Make 'effective_not_for_loan_status' fallback to 0 if itype has it undef

This patch makes the effective not for loan status be set the item value
if not defined at itype level.

To test:
1. Apply the regressions tests patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/items.t
=> FAIL: Tests fail!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 6 Marcel de Rooy 2023-10-27 06:09:44 UTC
Looking here
Comment 7 Marcel de Rooy 2023-10-27 06:15:46 UTC
Created attachment 157968 [details] [review]
Bug 35167: Regression tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 8 Marcel de Rooy 2023-10-27 06:15:48 UTC
Created attachment 157969 [details] [review]
Bug 35167: Make 'effective_not_for_loan_status' fallback to 0 if itype has it undef

This patch makes the effective not for loan status be set the item value
if not defined at itype level.

To test:
1. Apply the regressions tests patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/items.t
=> FAIL: Tests fail!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 9 Marcel de Rooy 2023-10-27 06:16:43 UTC
Shouldnt we at some point change the itemtypes table?

`notforloan` smallint(6) DEFAULT NULL COMMENT '1 if the item is not for loan, 0 if the item is available for loan',

Just inconsistent?
Comment 10 Tomás Cohen Arazi (tcohen) 2023-10-27 19:52:30 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 11 Fridolin Somers 2023-11-02 20:35:20 UTC
Pushed to 23.05.x for 23.05.05
Comment 12 Matt Blenkinsop 2023-11-13 15:11:45 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x