https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43836

            Bug ID: 43836
           Summary: Double-clicking Save in the basic MARC editor creates
                    two bibliographic records
   Initiative type: ---
        Sponsorship ---
            status:
           Product: Koha
           Version: 25.05
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P5 - low
         Component: Cataloging
          Assignee: [email protected]
          Reporter: [email protected]
        QA Contact: [email protected]
                CC: [email protected]
  Target Milestone: ---

When a cataloguer clicks "Save" twice in the basic MARC editor while the first
request is still being processed, Koha creates two bibliographic records with
consecutive biblionumbers.

There is no protection against a second submission: the save buttons are never
disabled and there is no in-flight flag.

koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (25.05.07):

  133  $("#saverecord").click(function(e){ e.preventDefault(); onOption(); });
  217  var onOption = function () { return Check(); }
  693  function Check(){ ... }
  719      document.f.submit();
  900  <form method="post" name="f" id="f"
action="/cgi-bin/koha/cataloguing/addbiblio.pl" onsubmit="return Check();"
class="marc_editor">

Every click runs Check() again, and Check() calls document.f.submit() again.
Each POST carries op=cud-add-biblio with an empty biblionumber, so addbiblio.pl
calls AddBiblio() once per request.

HOW WE FOUND IT

Production site, Koha 25.05.07, a single cataloguer. action_logs holds pairs of
CATALOGUING / ADD entries with consecutive biblionumbers, the same
borrowernumber, interface 'intranet', and the same timestamp down to the
second:

  2026-09-04 18:43:37  ADD 33565
  2026-09-04 18:43:37  ADD 33566
  2026-09-04 19:18:55  ADD 33569
  2026-09-04 19:18:55  ADD 33570

One episode produced three records in the same second. In each pair only one
record ends up with an item attached and the other stays empty, so the
duplicate is easy to spot afterwards, but nothing prevents it from being
created.

Nine episodes between 2026-08-31 and 2026-09-21, on a site that catalogues
around twenty records a month. No file or Z39.50 import was involved
(import_batches is empty for the period); all the records were created in the
basic MARC editor.

REPRODUCED OUTSIDE KOHA

A minimal page copying the same pattern (a form with onsubmit="return Check();"
where Check() calls document.f.submit()), posting to a server that waits 3
seconds before answering, which is what a slow save looks like:

  - one click: 1 POST
  - two clicks 400 ms apart: 2 POSTs, 406 ms apart

The delay is what makes it visible. With an instant response the page is
already unloading when the second click lands and only one request is sent,
which is why this is hard to see on an idle test instance and shows up on a
busy production server.

Pressing Enter in a field is NOT the cause. form.requestSubmit() fires
onsubmit, Check() calls document.f.submit(), and the browser aborts the
original submission, so only one POST is sent. We tested this before reporting.

TO REPRODUCE

1. Make the response slow: add a sleep to the cud-add-biblio branch of
cataloguing/addbiblio.pl, or use a loaded instance.
2. Cataloguing > New record, fill in the mandatory fields.
3. Click Save twice, roughly half a second apart.
4. Two records are created. Check with:
     SELECT biblionumber, title, timestamp FROM biblio ORDER BY biblionumber
DESC LIMIT 5;
   and look for two CATALOGUING / ADD rows with the same timestamp in
action_logs.

SUGGESTED FIX

Disable the save controls (#saverecord, #saveandview, #saveanditems,
#saveandcontinue) and set an in-flight flag the first time one of them is used,
along the lines of what bug 41922 proposes for the checkout form.
cataloguing/additem.pl and the authority editor look like they have the same
gap.

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to