I tried adding a tag to the default framework and got a 500 error. It was because the tag already existed. Elsewhere in Koha, we get a user readable message saying something like "An error occurred when inserting this patron category. The patron category might already exist." To replicate: 1. In the staff interface, go to Administration > MARC bibliographic framework 2. Click the Actions button next to the default framework and choose MARC structure 3. Click New tag 4. Fill out the form to add an already existing tag number Tag: 699 Label for lib: Local subject Label for OPAC: Local subject 5. Click Save changes --> 500 error
I've just had a librarian bump into this same issue today. (Turns out if you try to add a duplicate subfield, your new subfield overwrites the old subfield. Interesting!)
I've written a fix. It's not perfect, but I think it's good enough.
(In reply to David Cook from comment #2) > I've written a fix. It's not perfect, but I think it's good enough. I think a better solution would be to show the error message on the edit page, but that would involve more refactoring. This seemed like the shortest path forward... but no worries if people rather go the refactoring route.
Created attachment 170149 [details] [review] Bug 34346: Show error message instead of 500 for duplicate tags This change shows a user-friendly error message instead of a 500 error if adding a duplicate MARC tag to a MARC bibliographic framework. Test plan: 0. Add patch and koha-plack --reload kohadev 1. Go to http://localhost:8081/cgi-bin/koha/admin/marctagstructure.pl?searchfield=264&frameworkcode= 2. Click "New tag" 3. Enter "264" in "Tag:" field 4. Click "Save changes" 5. See error message on screen (instead of 500 error)
Created attachment 170150 [details] [review] Bug 34346: Tidy
Created attachment 170181 [details] [review] Bug 34346: Show error message instead of 500 for duplicate tags This change shows a user-friendly error message instead of a 500 error if adding a duplicate MARC tag to a MARC bibliographic framework. Test plan: 0. Add patch and koha-plack --reload kohadev 1. Go to http://localhost:8081/cgi-bin/koha/admin/marctagstructure.pl?searchfield=264&frameworkcode= 2. Click "New tag" 3. Enter "264" in "Tag:" field 4. Click "Save changes" 5. See error message on screen (instead of 500 error) Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Created attachment 170182 [details] [review] Bug 34346: Tidy Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Moving this to "Signed Off" as I think Owen intended to?
Created attachment 170429 [details] [review] Bug 34346: Show error message instead of 500 for duplicate tags This change shows a user-friendly error message instead of a 500 error if adding a duplicate MARC tag to a MARC bibliographic framework. Test plan: 0. Add patch and koha-plack --reload kohadev 1. Go to http://localhost:8081/cgi-bin/koha/admin/marctagstructure.pl?searchfield=264&frameworkcode= 2. Click "New tag" 3. Enter "264" in "Tag:" field 4. Click "Save changes" 5. See error message on screen (instead of 500 error) Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 34346: Tidy Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
(In reply to David Cook from comment #2) > I've written a fix. It's not perfect, but I think it's good enough. Thanks for your patch. Just noting the missing Koha objects for marc_tag_structure, and the nice mix of DBIx::Class and old DBI in this patch :)
Slightly adjusted error message inline: From: <div class="dialog message">MARC field not added to MARC bibliographic framework. MARC tag already exists in framework field.</div> To: <div class="dialog message">MARC field not added to MARC bibliographic framework. MARC tag already exists in framework.</div>
Pushed for 24.11! Well done everyone, thank you!
Backported to 24.05.x for upcoming 24.05.06