Bug 39752

Summary: Koha MarcOrder does not verify bibliographic record exists when adding order and items
Product: Koha Reporter: Nick Clemens (kidclamp) <nick>
Component: AcquisitionsAssignee: Matt Blenkinsop <matt.blenkinsop>
Status: Pushed to main --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: carthur
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
25.05.00
Circulation function:
Attachments: Bug 39752: Check for biblio existence when matches are found
Bug 39752: Check for biblio existence when matches are found
Bug 39752: (QA follow-up) Unit test
Bug 39752: Check for biblio existence when matches are found

Description Nick Clemens (kidclamp) 2025-04-25 17:40:14 UTC
393     my $match        = $matches->count ? $matches->next             : undef;
 394     my $biblionumber = $match          ? $match->candidate_match_id : 0;

 396     if ($biblionumber) {
 397         $import_record->status('imported')->store;
 398         if ( $overlay_action eq 'replace' ) {
 399             my $biblio = Koha::Biblios->find($biblionumber);
 400             $import_record->replace( { biblio => $biblio } );
 401         }
 402     } else {


import_record_matches does not have a foreign key to biblios

stage + import some records to Koha
stage again, matching on isbn - you should find matches form first import
delete the records that already exist in koha
SELECT * FROM import_record_matches
Note that the matches are still there

If you try adding these to a basket it will die because of the invalid match trying to be used as a bilbio
Comment 1 Matt Blenkinsop 2025-04-28 08:51:32 UTC
Created attachment 181576 [details] [review]
Bug 39752: Check for biblio existence when matches are found

Currently when adding to a basket from a new/staged file, we don't check whether a matched record still exists when importing. This patch changes the conditional check to be based on the existence of the biblio record rather than just on the biblionumber from the match

Test plan:
1) Stage and import a record into Koha
2) Stage the same record again, this time matching on ISBN
3) Check that the match has been found in the batch details
4) Delete the original record that you imported in step 1
5) Find a basket, and add to it from a staged file
6) Choose the file/record you imported in stage 2
7) Select the record and save to add the orders
8) You will get a 500 error
9) Apply patch and restart_all
10) Refresh the page to re-submit the form
11) The form should submit correctly
Comment 2 David Nind 2025-04-29 08:43:37 UTC
Created attachment 181639 [details] [review]
Bug 39752: Check for biblio existence when matches are found

Currently when adding to a basket from a new/staged file, we don't check whether a matched record still exists when importing. This patch changes the conditional check to be based on the existence of the biblio record rather than just on the biblionumber from the match

Test plan:
1) Stage and import a record into Koha
2) Stage the same record again, this time matching on ISBN
3) Check that the match has been found in the batch details
4) Delete the original record that you imported in step 1
5) Find a basket, and add to it from a staged file
6) Choose the file/record you imported in stage 2
7) Select the record and save to add the orders
8) You will get a 500 error
9) Apply patch and restart_all
10) Refresh the page to re-submit the form
11) The form should submit correctly

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 Nick Clemens (kidclamp) 2025-04-29 13:20:11 UTC
Created attachment 181656 [details] [review]
Bug 39752: (QA follow-up) Unit test

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 4 Nick Clemens (kidclamp) 2025-04-29 13:20:13 UTC
Created attachment 181657 [details] [review]
Bug 39752: Check for biblio existence when matches are found

Currently when adding to a basket from a new/staged file, we don't check whether a matched record still exists when importing. This patch changes the conditional check to be based on the existence of the biblio record rather than just on the biblionumber from the match

Test plan:
1) Stage and import a record into Koha
2) Stage the same record again, this time matching on ISBN
3) Check that the match has been found in the batch details
4) Delete the original record that you imported in step 1
5) Find a basket, and add to it from a staged file
6) Choose the file/record you imported in stage 2
7) Select the record and save to add the orders
8) You will get a 500 error
9) Apply patch and restart_all
10) Refresh the page to re-submit the form
11) The form should submit correctly

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 5 Katrin Fischer 2025-04-29 15:24:24 UTC
Pushed for 25.05!

Well done everyone, thank you!