Bugzilla – Attachment 187197 Details for
Bug 40910
Log pollution for undefined/empty barcodes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40910: Reduce log pollution for undefined/empty barcodes
Bug-40910-Reduce-log-pollution-for-undefinedempty-.patch (text/plain), 2.92 KB, created by
Kyle M Hall (khall)
on 2025-10-01 14:29:54 UTC
(
hide
)
Description:
Bug 40910: Reduce log pollution for undefined/empty barcodes
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2025-10-01 14:29:54 UTC
Size:
2.92 KB
patch
obsolete
>From a00b74fc7003a3bb721fef3b1fc01bc40debc41d Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= <tomascohen@theke.io> >Date: Tue, 30 Sep 2025 11:10:52 -0300 >Subject: [PATCH] Bug 40910: Reduce log pollution for undefined/empty barcodes >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch prevents warnings and DBIx::Class errors when C4::SIP::ILS::Item->new() >receives undefined, empty, or whitespace-only item_id values that could occur >from faulty plugins or malformed SIP requests. > >Changes: >- Add early validation for undefined/empty item_id before barcodedecode() >- Add validation for barcodedecode() result before Koha::Items->find() >- Add debug logging when barcodedecode empties a barcode (indicates misconfiguration) >- Prevent "Odd number of elements in anonymous hash" warnings >- Prevent DBIx::Class constraint validation errors >- No functional changes - behavior preserved for valid barcodes > >Test plan: >1. Apply the regression tests >2. Run: > $ ktd --shell > k$ prove t/db_dependent/SIP/Item.t >=> FAIL: Tests fail! >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Tests pass! >5. Tests cover: > - Valid barcode functionality (preserved) > - Undefined item_id (no warnings) > - Empty string item_id (no warnings) > - Whitespace-only item_id (no warnings) > - barcodedecode edge cases (tabs, newlines, mixed) > - Nonexistent barcodes (expected warnings preserved) >6. Verify no warnings in SIP logs for malformed requests >7. Sign off :-D > >Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/SIP/ILS/Item.pm | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) > >diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm >index 4aadb99f22d..b97a9f52bb9 100644 >--- a/C4/SIP/ILS/Item.pm >+++ b/C4/SIP/ILS/Item.pm >@@ -81,7 +81,26 @@ Missing POD for new. > sub new { > my ( $class, $item_id ) = @_; > my $type = ref($class) || $class; >- my $item = Koha::Items->find( { barcode => barcodedecode($item_id) } ); >+ >+ # Return early if item_id is undefined, empty, or whitespace-only >+ if ( !defined $item_id || $item_id eq '' || $item_id =~ /^\s*$/ ) { >+ siplog( "LOG_DEBUG", "new ILS::Item: empty or undefined item_id" ); >+ return; >+ } >+ >+ my $decoded_barcode = barcodedecode($item_id); >+ >+ # Return early if barcode decoding results in empty value >+ if ( !defined $decoded_barcode || $decoded_barcode eq '' ) { >+ siplog( >+ "LOG_DEBUG", >+ "new ILS::Item('%s'): barcode decoding resulted in empty value - possible misconfiguration or faulty plugin", >+ $item_id >+ ); >+ return; >+ } >+ >+ my $item = Koha::Items->find( { barcode => $decoded_barcode } ); > unless ($item) { > siplog( "LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id ); > warn "new ILS::Item($item_id) : No item '$item_id'."; >-- >2.39.5 (Apple Git-154)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40910
:
187106
|
187107
|
187195
|
187196
| 187197