Bug 34157 - Exporting labels as a barcode range can cause 500 error
Summary: Exporting labels as a barcode range can cause 500 error
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Label/patron card printing (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Hammat wele
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-29 18:30 UTC by Lucas Gass (lukeg)
Modified: 2025-06-07 18:58 UTC (History)
7 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes the "Error 500..." message generated when printing barcode ranges using the label creator, and where the layout type selected is "Bibliographic data precedes barcode" (Cataloging > Tools > Label creator).
Version(s) released in:
Circulation function:


Attachments
Bug 34157: Exporting labels as a barcode range can cause 500 error (2.35 KB, patch)
2024-02-19 19:46 UTC, Matthias Le Gac
Details | Diff | Splinter Review
Bug 34157: Exporting labels as a barcode range can cause 500 error (2.50 KB, patch)
2024-06-03 10:27 UTC, HKS3 Tadeusz Sośnierz
Details | Diff | Splinter Review
Bug 34157: (Follow up) Removed the debugging data (913 bytes, patch)
2024-10-09 20:14 UTC, Sukhmandeep
Details | Diff | Splinter Review
Bug 34157: Exporting labels as a barcode range can cause 500 error (2.31 KB, patch)
2025-03-05 17:56 UTC, Hammat wele
Details | Diff | Splinter Review
Bug 34157: (Follow up) Removed the debugging data (894 bytes, patch)
2025-03-05 17:57 UTC, Hammat wele
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass (lukeg) 2023-06-29 18:30:34 UTC
To recreate:
 
1. Make or edit a label layout. For "Choose layout type:" select " Bibliographic data precedes barcode".
2. Label creator > New > Barcode range
3. Choose a barcode range.
4. Choose the layout from above.
5. 500 error:

Can't call method "metadata" on an undefined value at /usr/share/koha/lib/C4/Labels/Label.pm line 342.


Seems like this is related to Bug 29697.
Comment 1 Katrin Fischer 2023-07-16 13:36:08 UTC
I am not sure about this one. 

I was thinking of barcode range as a feature to pre-produce labels. So you can than add them to the items and scan them in at the same time when cataloguing.

I believe as the range allows for you to enter any number and isn't linking to existing items, it probably won't/can't work with labels using bibliographic information.

Maybe we need to catch this in a nicer way?
Comment 2 Heather Hernandez 2023-07-17 18:54:57 UTC
We stumbled on this bug.  Yes--we use printing a barcode range to pre-produce labels, to put on an item and then wand in to an item record (e.g., receiving a serial issue, cataloging a book, etc.)  But we want our library name on the barcode, so were experimenting with trying to get our library name on the label and discovered this "500 error."

Our experimenting is related to bug 31507, "When printing barcode range labels library name does not print."

--h2
Comment 3 Katrin Fischer 2023-07-17 20:53:08 UTC
Hi Heather, thx for commenting, that makes a lot of sense actually. I think this is bug 12316 (that I closed prematurely not thinking of this use case).
Comment 4 Heather Hernandez 2023-07-17 20:58:10 UTC
And thank you for mentioning that other bug, Katrin--I'll go comment on that one!

Cheerio!
h2
Comment 5 Marie-Luce Laflamme 2024-02-08 16:54:39 UTC
Same here. Barcode range is mainly used to print them in advance. Strangely, the same barcode range can't have different results.
When we stick to just barcodes in the layout, it works like a charm. But if we add free text (e.g. 'City library') in the there, we hit a 500 error.
Comment 6 Marie-Luce Laflamme 2024-02-08 17:37:42 UTC
The layout option 'bibliographic data precedes barcode' appears to rely on itemnumber, which it isn't ideal when printing a barcode range.



Before the test

Layout
- Add a new layout including free text
- choose layout type: 'bibliographic data precedes barcode'
- Add text between quotation marks in the list fields  (e.g. 'Centrale library')
- Save

Itemnumber check
- Find your database max(itemnumber)


Barcode check
- Find a barcode range 1 that is not currently in your database
    notes:  max(barcode) can be a good start.
            This range should be smaller < than max(itemnumber)
- Find another barcode range 2 that is not currently in your database
        This second range of numbers should be larger > than max(itemnumber)

Test plan
1. In Label creator > Add > Barcode range
2. Enter your barcode range 1; the one smaller < max(itemnumber)
3. Click on "Print range"
4. Choose the layout from above
5. Click on "Export"
6. View the pdf
  --> ok, Koha is printing text on each label   
7. Redo steps 2 to 3 with the barcode range 2; the one larger > max(itemnumber)
8. Select the DEFAULT layout
9. Check the pdf
  --> Koha generate all barcodes correctly
10. Keep your barcode range 2 and redo steps 2 to 3, but...
11. Select the layout with text previously added
12. Check the pdf
  --> Koha open up a 500 error page or empty page
Comment 7 Matthias Le Gac 2024-02-19 19:46:16 UTC
Created attachment 162282 [details] [review]
Bug 34157: Exporting labels as a barcode range can cause 500 error

The layout option 'bibliographic data precedes barcode' appears to rely on itemnumber, which it isn't ideal when printing a barcode range.



Before the test

Layout
- Add a new layout including free text
- choose layout type: 'bibliographic data precedes barcode'
- Add text between quotation marks in the list fields  (e.g. 'Centrale library')
- Save

Itemnumber check
- Find your database max(itemnumber)


Barcode check
- Find a barcode range 1 that is not currently in your database
    notes:  max(barcode) can be a good start.
            This range should be smaller < than max(itemnumber)
- Find another barcode range 2 that is not currently in your database
        This second range of numbers should be larger > than max(itemnumber)

Test plan
1. In Label creator > Add > Barcode range
2. Enter your barcode range 1; the one smaller < max(itemnumber)
3. Click on "Print range"
4. Choose the layout from above
5. Click on "Export"
6. View the pdf
  --> ok, Koha is printing text on each label   
7. Redo steps 2 to 3 with the barcode range 2; the one larger > max(itemnumber)
8. Select the DEFAULT layout
9. Check the pdf
  --> Koha generate all barcodes correctly
10. Keep your barcode range 2 and redo steps 2 to 3, but...
11. Select the layout with text previously added
12. Check the pdf
  --> Koha open up a 500 error page or empty page
13. apply the patch
14. Perform the same steps as before, but this time without encountering any errors. Koha is printing text on each label during step 12.
Comment 8 HKS3 Tadeusz Sośnierz 2024-06-03 10:27:03 UTC
Created attachment 167338 [details] [review]
Bug 34157: Exporting labels as a barcode range can cause 500 error

Signed-off-by: Tadeusz „tadzik” Sośnierz <tadeusz@sosnierz.com>


Seems to contain some leftover debug code: `print STDERR "label_a: iffffffff";` in `label-create-pdf.pl`
Comment 9 Kyle M Hall (khall) 2024-10-07 14:08:34 UTC
Looks like the patch has some debugging data in it?

print STDERR "label_a: iffffffff";
Comment 10 Sukhmandeep 2024-10-09 20:14:25 UTC
Created attachment 172577 [details] [review]
Bug 34157: (Follow up) Removed the debugging data
Comment 11 Rudy Hinojosa 2025-01-16 17:30:51 UTC
Just a side note, the same range used in barcode batches works fine, it's the barcode range feature that has the 500 error in 24.11. Looking at the post URL I notice it is attempting to use batch #0. That might be ok if that's intended to be a programmatic cross reference to internal routines maybe.
Comment 12 Hammat wele 2025-03-05 17:56:40 UTC
Created attachment 179001 [details] [review]
Bug 34157: Exporting labels as a barcode range can cause 500 error

Signed-off-by: Tadeusz „tadzik” Sośnierz <tadeusz@sosnierz.com>
Comment 13 Hammat wele 2025-03-05 17:57:02 UTC
Created attachment 179002 [details] [review]
Bug 34157: (Follow up) Removed the debugging data
Comment 14 David Nind 2025-06-07 06:23:06 UTC
I had a go at testing. The patch still applies.

As I understand it, this bug fixes the error 500 if you use the "Bibliographic data precedes barcode" layout type when printing a barcode range.

I'm happy to sign off, however the QA script complains:

 FAI    C4/Labels/Label.pm
   FAIL   tidiness
                 File is not tidy, please run `perl misc/devel/tidy.pl C4/Labels/Label.pm`

The commit messages also need to follow the commit message guidelines https://wiki.koha-community.org/wiki/Commit_messages

I also changed the assignee.

Testing notes (using KTD):
1. Set up information for testing:
   1.1 Create a new label layout:
       1.1.1 Cataloging > Tools > Label creator
       1.1.2 New > Label layout
       1.1.3 Add these details:
             - Layout name: BZ34157
             - Choose layout type: Bibliographic data precedes barcode
             - Select 'List fieds'
             - Data fields: add some text at the end
                title, author, isbn, issn, itemtype, barcode, itemcallnumber, 'Some text'
       1.1.3 Save
   1.2 Ranges of barcode numbers for testing:
       1.2.1 Where the numbers are not used in KTD, and are LOWER than the highest barcode number (39999000019193): 500000 to 500100
       1.2.3 Where the numbers are not used in KTD, and are HIGHER than the highest barcode number (39999000019193): 39999000020000 to 39999000020100
       1.2.2 Where the numbers are used in KTD: 3999900000001 to 3999900001001
2. Print a barcode range using the ranges in 1.2: 
   2.1 Cataloging > Tools > Label creator > Print barcode range
   2.2 Enter the barcode ranges
   2.3 Select a layout to be applied: BZ34157
   2.4 Export
   2.5 Click "Download as PDF"
   2.6 Results for all barcode ranges: 
       ==> You get a page with "An error has occured! Error 500...".
3. Repeat step 2, but select the DEFAULT layout for 2.3:
   ==> Results for all barcode ranges: PDFs with barcode labels successfully generated
4. Apply the patches and restart everything (restart_all)
5. Repeat steps 2 and 3.
6. Results for all barcode ranges and the BZ34157 and DEFAULT layouts:
   ==> PDFs with barcode labels successfully generated
Comment 15 David Nind 2025-06-07 18:58:29 UTC
Changed importance from enhancement to normal - a 500 errors means something is not working as it should.