solgenomics / sgn

The code behind the Sol Genomics Network, Cassavabase and other Breedbase websites
https://solgenomics.net
MIT License
66 stars 34 forks source link

`merge_stocks.pl` script fails due to `stock_allele` associations #4512

Closed dwaring87 closed 1 year ago

dwaring87 commented 1 year ago

Expected Behavior

If the 'bad' stock has associated loci stored in the stock_allele table, the merge script will fail when trying to remove the 'bad' stock:

Delete merged stocks ( -x option)...
Deleting stock WI_X8177-1 (id=106664)
An ERROR occurred (DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::Pg::st execute failed: ERROR:  update or delete on table "stock" violates foreign key constraint "stock_allele_stock_id_fkey" on table "stock_allele"
DETAIL:  Key (stock_id)=(106664) is still referenced from table "stock_allele". at ./merge_stocks.pl line 118
). Rolling back changes...

For Bugs:

Environment

Steps to Reproduce

dwaring87 commented 1 year ago

More details:

In this particular case, the CXGN::Stock merge function failed to merge two stocks because they had different pedigrees, but the merge script still tries to delete the 'bad' stock from the database.

Should the merge script exit with an error if the merge function fails? Or should it skip the failed merge (and not attempt to delete the stock) and continue with the rest of the merges?

bellerbrock commented 1 year ago

Here's the patch that added missing cascade deletes. Looks like it didn't touch stock_allele table though.

dwaring87 commented 1 year ago

@lukasmueller The topic/merge_stock_errors branch updates the CXGN::Stock merge function to return an error message if the checks don't pass. Then, the merge_stocks.pl script will skip the bad stock deletion when an error is returned when trying to merge. It doesn't add any cascade deletes.