Bug 34346 - Adding duplicate tag to a framework should give user readable message
Summary: Adding duplicate tag to a framework should give user readable message
Status: Pushed to stable
Alias: None
Product: Koha
Classification: Unclassified
Component: MARC Bibliographic data support (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low minor
Assignee: David Cook
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-21 20:57 UTC by Caroline Cyr La Rose
Modified: 2024-11-18 18:57 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00,24.05.06
Circulation function:


Attachments
Bug 34346: Show error message instead of 500 for duplicate tags (5.79 KB, patch)
2024-08-08 01:32 UTC, David Cook
Details | Diff | Splinter Review
Bug 34346: Tidy (2.83 KB, patch)
2024-08-08 01:32 UTC, David Cook
Details | Diff | Splinter Review
Bug 34346: Show error message instead of 500 for duplicate tags (5.84 KB, patch)
2024-08-09 11:03 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 34346: Tidy (2.88 KB, patch)
2024-08-09 11:04 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 34346: Show error message instead of 500 for duplicate tags (6.00 KB, patch)
2024-08-16 07:12 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 Caroline Cyr La Rose 2023-07-21 20:57:56 UTC
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
Comment 1 David Cook 2024-08-08 00:48:37 UTC
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!)
Comment 2 David Cook 2024-08-08 01:26:19 UTC
I've written a fix. It's not perfect, but I think it's good enough.
Comment 3 David Cook 2024-08-08 01:31:56 UTC
(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.
Comment 4 David Cook 2024-08-08 01:32:22 UTC
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)
Comment 5 David Cook 2024-08-08 01:32:25 UTC
Created attachment 170150 [details] [review]
Bug 34346: Tidy
Comment 6 Owen Leonard 2024-08-09 11:03:58 UTC
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>
Comment 7 Owen Leonard 2024-08-09 11:04:00 UTC
Created attachment 170182 [details] [review]
Bug 34346: Tidy

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 8 David Cook 2024-08-12 00:40:58 UTC
Moving this to "Signed Off" as I think Owen intended to?
Comment 9 Marcel de Rooy 2024-08-16 07:12:14 UTC
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>
Comment 10 Marcel de Rooy 2024-08-16 07:13:35 UTC
(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 :)
Comment 11 Katrin Fischer 2024-08-19 15:04:54 UTC
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>
Comment 12 Katrin Fischer 2024-08-19 15:31:01 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 13 Lucas Gass (lukeg) 2024-11-18 18:57:39 UTC
Backported to 24.05.x for upcoming 24.05.06