Bug 34689 - Add and duplicate item - Error 500
Summary: Add and duplicate item - Error 500
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: Main
Hardware: All All
: P3 normal
Assignee: Matt Blenkinsop
QA Contact: Testopia
URL:
Keywords:
Depends on: 27526
Blocks:
  Show dependency treegraph
 
Reported: 2023-09-01 11:53 UTC by Christophe TORIN
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.11
Circulation function:


Attachments
Bug 34689: Ignore itemnumber when creating item hash (1.60 KB, patch)
2023-09-29 12:53 UTC, Matt Blenkinsop
Details | Diff | Splinter Review
Bug 34689: Ignore itemnumber when creating item hash (1.63 KB, patch)
2023-09-30 05:14 UTC, David Nind
Details | Diff | Splinter Review
Bug 34689: Ignore itemnumber when creating item hash (1.69 KB, patch)
2023-10-01 21:00 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe TORIN 2023-09-01 11:53:39 UTC
Test case :

- Select any biblio
- Add an item
- fill the form, and submit with the "Add & duplicate" button
- Item is added, and the form is duplicated
- Fill the missing info (barcode), and save the new item
- Error 500

In koha logs, I have the following error :
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Duplicate entry '1100882' for key 'PRIMARY' at /home/koha/src/Koha/Object.pm line 170

After investigations, the id 1100882 is the id of the item that was added before.

It looks like the new itemnumber is still present after duplicate !

Thanks,
Christophe
Comment 1 Martin Renvoize (ashimema) 2023-09-14 10:38:58 UTC
Confirmed.. looking into it now
Comment 2 Martin Renvoize (ashimema) 2023-09-14 13:35:40 UTC
I can't for the life of me replicate this locally on a 22.11 checkout (or master).. but I can replicate it on a live site.. there must be something in the configuration that's causing this somewhere but I'm not seeing it yet.
Comment 3 Jonathan Druart 2023-09-18 20:41:31 UTC
Christophe, which exact version of Koha are you using? Do you recreate the problem on a sandbox?
Comment 4 Matt Blenkinsop 2023-09-29 12:36:32 UTC
I've traced the issue on this and managed to re-produce in KTD. It depends on the MARC framework you are using and what you have in the 952 field for the itemnumber field (subfield 9). If that subfield (952$9) is set to anything other than "ignore" in the "Managed in tab" then it will pull the item number that has just been created from the UI and try to add that as part of the duplicated item. We need to tell the duplication code to ignore the itemnumber field

Patch incoming
Comment 5 Matt Blenkinsop 2023-09-29 12:53:03 UTC
Created attachment 156390 [details] [review]
Bug 34689: Ignore itemnumber when creating item hash

A primary key error can be thrown when an item number is included in a new title hash. We need the item creation to ignore an itemnumber even if it is included in a MARC Framework

Test plan:
1) Edit the MARC framework relating to books (BKS in KTD)
2) In the 952$9 field (Koha itemnumber (autogenerated)), change the value of "Managed in tab" to "items (10)"
3) In the catalog, find a record that uses that MARC framework
4) Click "New" and choose to add a new item
5) Enter a barcode and click the "Add & duplicate" button
6) The page will refresh and an item will have been added
7) Enter a new barcode and click the same button again
8) An error will be thrown
9) Click the back button in the browser
10) Apply patch and restart_all
11) Click the add and duplicate button again
12) This time no error will be thrown and the page will refresh with another new item added
13) Sign off!
Comment 6 David Nind 2023-09-30 05:14:54 UTC
Created attachment 156431 [details] [review]
Bug 34689: Ignore itemnumber when creating item hash

A primary key error can be thrown when an item number is included in a new title hash. We need the item creation to ignore an itemnumber even if it is included in a MARC Framework

Test plan:
1) Edit the MARC framework relating to books (BKS in KTD)
2) In the 952$9 field (Koha itemnumber (autogenerated)), change the value of "Managed in tab" to "items (10)"
3) In the catalog, find a record that uses that MARC framework
4) Click "New" and choose to add a new item
5) Enter a barcode and click the "Add & duplicate" button
6) The page will refresh and an item will have been added
7) Enter a new barcode and click the same button again
8) An error will be thrown
9) Click the back button in the browser
10) Apply patch and restart_all
11) Click the add and duplicate button again
12) This time no error will be thrown and the page will refresh with another new item added
13) Sign off!

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 Victor Grousset/tuxayo 2023-10-01 21:00:31 UTC
Created attachment 156451 [details] [review]
Bug 34689: Ignore itemnumber when creating item hash

A primary key error can be thrown when an item number is included in a new title hash. We need the item creation to ignore an itemnumber even if it is included in a MARC Framework

Test plan:
1) Edit the MARC framework relating to books (BKS in KTD)
2) In the 952$9 field (Koha itemnumber (autogenerated)), change the value of "Managed in tab" to "items (10)"
3) In the catalog, find a record that uses that MARC framework
4) Click "New" and choose to add a new item
5) Enter a barcode and click the "Add & duplicate" button
6) The page will refresh and an item will have been added
7) Enter a new barcode and click the same button again
8) An error will be thrown
9) Click the back button in the browser
10) Apply patch and restart_all
11) Click the add and duplicate button again
12) This time no error will be thrown and the page will refresh with another new item added
13) Sign off!

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 8 Victor Grousset/tuxayo 2023-10-01 21:05:24 UTC
Works, makes sense, QA script happy, code looks good, passing QA :)
Comment 9 Jonathan Druart 2023-10-04 07:15:55 UTC
We need confirmation from Christophe that the patch fixes his problem.
Comment 10 Christophe TORIN 2023-10-04 07:37:07 UTC
Hi,

I just applied the patch on our platform and it fixes the problem on our side !

Thank you
Comment 11 Jonathan Druart 2023-10-04 09:01:30 UTC
(In reply to Christophe TORIN from comment #10)
> Hi,
> 
> I just applied the patch on our platform and it fixes the problem on our
> side !
> 
> Thank you

Great, thanks for the quick reply!
Comment 12 Tomás Cohen Arazi (tcohen) 2023-10-04 13:14:57 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 13 Fridolin Somers 2023-10-05 19:46:13 UTC
Pushed to 23.05.x for 23.05.05
Comment 14 Matt Blenkinsop 2023-10-17 16:56:53 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x