[Bug 41097] New: Deduping authorities script (dedup_authorities.pl) can die on duplicated ids
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Bug ID: 41097 Summary: Deduping authorities script (dedup_authorities.pl) can die on duplicated ids Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Command-line Utilities Assignee: koha-bugs@lists.koha-community.org Reporter: nick@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org CC: robin@catalyst.net.nz When running the script it seems to generate duplicate ids: Processing authority 1660 (531/650 81.69%) Merging 1660,1662 into 1660. Updated 0 biblios Deleting 1662 Merge done. This seems to be a product of _choose_records which gets all the candidates, but then adds the original record twice 318 my @records = map { C4::AuthoritiesMarc::GetAuthority($_) } @recordids; 319 my @candidate_auths = @records; and later: $choose_subs[2] ? $choose_subs[2]->($_) : 0 ] => ( $records[0], @candidate_auths ); -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 --- Comment #1 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 188416 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=188416&action=edit Bug 41097: Don't use original record twice This patch prevents us from passing the same record twice into the choose subs to avoid a situation where the original record is not chosen as the one to keep and we try to merge/delete the same record twice To test: 1 - Run the script on a test system that you can reset perl misc/maintenance/dedup_authorities.pl -v -v --confirm -a="PERSO_NAME" 2 - Note duplication of entries in the output like: Merging 1660,1662 into 1660. Updated 0 biblios Deleting 1662 Merge done. 3 - Note how many records are merged 4 - Run again to confirm nothing is merged, i.e. the script removed the dupes 5 - Reset your DB 6 - Apply patch 7 - Run the script again 8 - Note entries no longer have duplicated ids: Merging 1662 into 1660. 9 - Note the same number of records are merged 10 - Run again and confirm nothing is merged 11 - Sign off! -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |13706 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13706 [Bug 13706] Deduping authorities script (dedup_authorities.pl) -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |nick@bywatersolutions.com |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #188416|0 |1 is obsolete| | --- Comment #2 from David Nind <david@davidnind.com> --- Created attachment 188437 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=188437&action=edit Bug 41097: Don't use original record twice This patch prevents us from passing the same record twice into the choose subs to avoid a situation where the original record is not chosen as the one to keep and we try to merge/delete the same record twice To test: 1 - Run the script on a test system that you can reset perl misc/maintenance/dedup_authorities.pl -v -v --confirm -a="PERSO_NAME" 2 - Note duplication of entries in the output like: Merging 1660,1662 into 1660. Updated 0 biblios Deleting 1662 Merge done. 3 - Note how many records are merged 4 - Run again to confirm nothing is merged, i.e. the script removed the dupes 5 - Reset your DB 6 - Apply patch 7 - Run the script again 8 - Note entries no longer have duplicated ids: Merging 1662 into 1660. 9 - Note the same number of records are merged 10 - Run again and confirm nothing is merged 11 - Sign off! Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |david@davidnind.com Text to go in the| |This fixes the deduping release notes| |authorities maintenance | |script | |(misc/maintenance/dedup_aut | |horities.pl) so that it now | |works and displays the | |output from the merging of | |authority records as | |expected. | | | |Previously, it seemed to | |generate duplicate IDs, for | |example: | | | |Before | |------ | | | |Processing authority 1660 | |(531/650 81.69%) | | Merging 1660,1662 into | |1660. | | Updated 0 biblios | | Deleting 1662 | | Merge done. | | | |After | |----- | | | |Processing authority 1660 | |(532/650 81.85%) | | Merging 1662 into 1660. | | Updated 0 biblios | | Deleting 1662 | | Merge done. --- Comment #3 from David Nind <david@davidnind.com> --- Testing notes (using KTD) - just noting my experience, have signed off: Before the patch ================== First run --------- ... Processing authority 748 (360/650 55.38%) Merging 748,748 into 403. Updated 0 biblios Deleting 748 Updated 0 biblios Deleting 748 {UNKNOWN}: Can't call method "move_to_deleted" on an undefined value at /kohadevbox/koha/C4/AuthoritiesMarc.pm line 754. at /kohadevbox/koha/C4/AuthoritiesMarc.pm line 757 Second run, still get merges ---------------------------- ... Processing authority 1568 (514/597 86.10%) Merging 1568,1568 into 403. Updated 0 biblios Deleting 1568 Updated 0 biblios Deleting 1568 {UNKNOWN}: Can't call method "move_to_deleted" on an undefined value at /kohadevbox/koha/C4/AuthoritiesMarc.pm line 754. at /kohadevbox/koha/C4/AuthoritiesMarc.pm line 757 Third run --------- End of deduping for authtype 'PERSO_NAME' Updated 0 biblios Deleted 6 authorities No biblios to update Fourth run ---------- End of deduping for authtype 'PERSO_NAME' Updated 0 biblios Deleted 0 authorities No biblios to update After the patch - with a reset_all ================================== ... Processing authority 1662 (631/650 97.08%) Merging 1660 into 1662. Updated 0 biblios Deleting 1660 Merge done. .... End of deduping for authtype 'PERSO_NAME' Updated 0 biblios Deleted 50 authorities No biblios to update After the patch - with a shutdown and startup of KTD ==================================================== First run --------- ... Processing authority 1660 (532/650 81.85%) Merging 1662 into 1660. Updated 0 biblios Deleting 1662 Merge done. ... End of deduping for authtype 'PERSO_NAME' Updated 0 biblios Deleted 104 authorities No biblios to update Second run ---------- ... End of deduping for authtype 'PERSO_NAME' Updated 0 biblios Deleted 0 authorities No biblios to update -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Failed QA CC| |m.de.rooy@rijksmuseum.nl --- Comment #4 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Looking at the code: This seems to be the only call: my ( $recordid_to_keep, @recordids_to_merge ) = _choose_records( $authority->authid, @recordids ); The POD says: returns first the record to merge to and list of records to merge from The sub makes no distinction between $authority->authid and @recordids. Note btw that @recordids is a BAD name; it contains MARC records ! sub _choose_records { my @recordids = @_; It returns candidate authids (picked from 001) but they are sorted. Why should the original first argument still be first? Shouldnt we add the first parameter (which is NOT a MARC record), not include that one while sorting and push it in front when returning values? This needs a bit more attention to clarify current obscureness while touching those lines here. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |m.de.rooy@rijksmuseum.nl |y.org | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Signed Off --- Comment #5 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- (In reply to Marcel de Rooy from comment #4)
Looking at the code:
This seems to be the only call: my ( $recordid_to_keep, @recordids_to_merge ) = _choose_records( $authority->authid, @recordids );
The POD says: returns first the record to merge to and list of records to merge from
The sub makes no distinction between $authority->authid and @recordids. Note btw that @recordids is a BAD name; it contains MARC records ! sub _choose_records { my @recordids = @_;
It returns candidate authids (picked from 001) but they are sorted. Why should the original first argument still be first?
It shouldn't - I think that was just a mistake
Shouldn't we add the first parameter (which is NOT a MARC record), not include that one while sorting and push it in front when returning values?
The whole point of sorting is to determine the best candidate to merge into, and we don't know which record that is before we sort. Julian wrote the original, I just got it through QA, so I can't say why we originally wanted the first record, but I think the testing can demonstrate we don't want the same record id and to end up trying to merge into the same record
This needs a bit more attention to clarify current obscureness while touching those lines here.
I welcome any additions to clarify the code, but I do think this fix is pretty striaghtforward -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Small patch Status|Signed Off |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #188437|0 |1 is obsolete| | --- Comment #6 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 193502 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=193502&action=edit Bug 41097: Don't use original record twice This patch prevents us from passing the same record twice into the choose subs to avoid a situation where the original record is not chosen as the one to keep and we try to merge/delete the same record twice To test: 1 - Run the script on a test system that you can reset perl misc/maintenance/dedup_authorities.pl -v -v --confirm -a="PERSO_NAME" 2 - Note duplication of entries in the output like: Merging 1660,1662 into 1660. Updated 0 biblios Deleting 1662 Merge done. 3 - Note how many records are merged 4 - Run again to confirm nothing is merged, i.e. the script removed the dupes 5 - Reset your DB 6 - Apply patch 7 - Run the script again 8 - Note entries no longer have duplicated ids: Merging 1662 into 1660. 9 - Note the same number of records are merged 10 - Run again and confirm nothing is merged 11 - Sign off! Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 --- Comment #7 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Created attachment 193503 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=193503&action=edit Bug 41097: (QA follow-up) Clarify POD Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 --- Comment #8 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to Nick Clemens (kidclamp) from comment #5)
I welcome any additions to clarify the code, but I do think this fix is pretty striaghtforward
The fix looks simple, the existing code was a bit obscure. The POD was unclear too. I have tried to fix the latter here with a small follow-up. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to main Version(s)| |26.05.00 released in| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 --- Comment #9 from Lucas Gass (lukeg) <lucas@bywatersolutions.com> --- Nice work everyone! Pushed to main for 26.05 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 Jacob O'Mara <jacob.omara@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to main |Pushed to stable Version(s)|26.05.00 |26.05.00,25.11.04 released in| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41097 --- Comment #10 from Jacob O'Mara <jacob.omara@openfifth.co.uk> --- Thanks all, pushed to 25.11.x -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org