Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch
Summary: Create labels action fails in manage-marc-import.pl if an item has been delet...
Status: Pushed to Stable
Alias: None
Product: Koha
Classification: Unclassified
Component: Label/patron card printing (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Nick Clemens
QA Contact: Marcel de Rooy
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-15 16:37 UTC by Barton Chittenden
Modified: 2017-06-05 12:46 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch. (1.61 KB, patch)
2017-05-16 09:43 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch. (1.73 KB, patch)
2017-05-23 18:25 UTC, Josef Moravec
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 18611 - Followup, remove tabs to make qa tools happy (1.68 KB, patch)
2017-05-23 18:25 UTC, Josef Moravec
Details | Diff | Splinter Review
Bug 18611 - Followup, remove tabs to make qa tools happy (1.68 KB, patch)
2017-05-23 18:26 UTC, Josef Moravec
Details | Diff | Splinter Review
Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch. (1.81 KB, patch)
2017-05-26 08:27 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18611 - Followup, remove tabs to make qa tools happy (1.85 KB, patch)
2017-05-26 08:27 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18611: [QA Follow-up] Make SQL query more readable (1.40 KB, patch)
2017-05-26 08:27 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18611: [QA Follow-up] Add unit test for GetItemNumbersFromImportBatch (2.78 KB, patch)
2017-05-26 08:27 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 Barton Chittenden 2017-05-15 16:37:40 UTC
On the manage marc import screen, clicking Import Batch on a batch containing a deleted item gives the message "Error attempting to create label batch. Please ask your system administrator to check the log for more details.", and creates an empty PDF file.

To replicate:

1) Import a marc record including items.
2) Delete one of the items in the batch.
3) In Home › Tools › Manage staged MARC records, click '(Create label batch)' on the batch in question.
4) This will show the message "Error attempting to create label batch. Please ask your system administrator to check the log for more details."

The logs in /var/log/koha/INSTANCE/intranet-error.log will look like this:

123456

[Mon May 15 11:14:21.848772 2017] [cgi:error] [pid 15635] [client a.b.c.d:xxxxx] AH01215: [Mon May 15 11:14:21 2017] manage-marc-import.pl: DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha_xyzzy`.`creator_batches`, CONSTRAINT `creator_batches_ibfk_3` FOREIGN KEY (`item_number`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE) [for Statement "INSERT INTO creator_batches (batch_id, item_number, branch_code, creator) VALUES (?,?,?,?);" with ParamValues: 0=164, 1=123456, 2="APL", 3='Labels'] at /usr/share/koha/lib/C4/Creators/Batch.pm line 69., referer: http://asdfsadf...
[Mon May 15 11:14:21.849012 2017] [cgi:error] [pid 15635] [client a.b.c.d:xxxxx] AH01215: [Mon May 15 11:14:21 2017] manage-marc-import.pl: Database returned the following error on attempted INSERT: Cannot add or update a child row: a foreign key constraint fails (`koha_xyzzy`.`creator_batches`, CONSTRAINT `creator_batches_ibfk_3` FOREIGN KEY (`item_number`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE) at /usr/share/koha/lib/C4/Creators/Batch.pm line 71., referer: http://asdfsadf...
[Mon May 15 11:14:21.849147 2017] [cgi:error] [pid 15635] [client a.b.c.d:xxxxx] AH01215: [Mon May 15 11:14:21 2017] manage-marc-import.pl: create_labelbatch_from_importbatch() : Error attempting to add item #123456 of import batch #11048 to label batch. at /usr/share/koha/intranet/cgi-bin/tools/manage-marc-import.pl line 198., referer: http://asdfsadf
...

I think we need to have /usr/share/koha/lib/C4/Creators/Batch.pm exclude items where the itemnumber is null.
Comment 1 Barton Chittenden 2017-05-15 17:08:38 UTC
As a work-around, create a report of valid barcodes in a given import batch using the query found here:

https://wiki.koha-community.org/wiki/SQL_Reports_Library#Workaround_for_Bug_18611
Comment 2 Nick Clemens 2017-05-16 09:43:51 UTC
Created attachment 63483 [details] [review]
Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch.

To test:
1 - Import a batch with some items
2 - Delete one of the imported items
3 - Browse to Tools->Staged MARC record management
4 - Click (Create label batch) for the batch you imported
5 - Recieve an error
6 - Apply patch
7 - Click (Create label batch)
8 - Batch is created with remaning items from the import
Comment 3 Josef Moravec 2017-05-23 18:25:42 UTC
Created attachment 63667 [details] [review]
Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch.

To test:
1 - Import a batch with some items
2 - Delete one of the imported items
3 - Browse to Tools->Staged MARC record management
4 - Click (Create label batch) for the batch you imported
5 - Recieve an error
6 - Apply patch
7 - Click (Create label batch)
8 - Batch is created with remaning items from the import

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 4 Josef Moravec 2017-05-23 18:25:46 UTC
Created attachment 63668 [details] [review]
[SIGNED-OFF] Bug 18611 - Followup, remove tabs to make qa tools happy

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 5 Josef Moravec 2017-05-23 18:26:35 UTC
Created attachment 63669 [details] [review]
Bug 18611 - Followup, remove tabs to make qa tools happy

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 6 Marcel de Rooy 2017-05-26 08:27:27 UTC
Created attachment 63728 [details] [review]
Bug 18611 - Create labels action fails in manage-marc-import.pl if an item has been deleted from the import batch.

To test:
1 - Import a batch with some items
2 - Delete one of the imported items
3 - Browse to Tools->Staged MARC record management
4 - Click (Create label batch) for the batch you imported
5 - Recieve an error
6 - Apply patch
7 - Click (Create label batch)
8 - Batch is created with remaning items from the import

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Marcel de Rooy 2017-05-26 08:27:32 UTC
Created attachment 63729 [details] [review]
Bug 18611 - Followup, remove tabs to make qa tools happy

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 8 Marcel de Rooy 2017-05-26 08:27:36 UTC
Created attachment 63730 [details] [review]
Bug 18611: [QA Follow-up] Make SQL query more readable

Make it more explicit by adding join statements.

Test plan:
See next patch for adding a unit test.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 9 Marcel de Rooy 2017-05-26 08:27:40 UTC
Created attachment 63731 [details] [review]
Bug 18611: [QA Follow-up] Add unit test for GetItemNumbersFromImportBatch

Test plan:
Run t/db_dependent/ImportBatch.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 10 Kyle M Hall 2017-05-29 02:24:14 UTC
Pushed to master for 17.05, thanks Nick, Josef, Marcel!
Comment 11 Katrin Fischer 2017-06-05 12:46:27 UTC
These patches have been pushed to 16.11.x and will be in 16.11.09.