[Bug 24741] New: Recent creation of unique index on library_groups erroneously removes rows
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 Bug ID: 24741 Summary: Recent creation of unique index on library_groups erroneously removes rows Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: critical Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: stefan.berndtsson@ub.gu.se QA Contact: testopia@bugs.koha-community.org Bug 21674 introduces a new unique index on library_groups. Before this is done, removal of duplicate entries is done. This check for duplicates is wrong and removes non-duplicate entries as well. The query being executed is: DELETE FROM library_groups WHERE id NOT IN ( SELECT MIN(id) FROM ( SELECT * FROM library_groups ) AS lg WHERE parent_id IS NOT NULL GROUP BY parent_id, branchcode ) AND parent_id IS NOT NULL; To test: Use Administration/Library groups, add two group on the same level. Add a library or two in each of them, then run the above query. The second of the two groups, including all its libraries will now be removed. -- 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=24741 David Gustafsson <glasklas@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |glasklas@gmail.com --- Comment #1 from David Gustafsson <glasklas@gmail.com> --- I'm not 100%, but think a correct query to remove duplicates could be written like: DELETE FROM library_groups WHERE id NOT IN ( SELECT MIN(id) FROM ( SELECT * FROM library_groups ) AS lg GROUP BY parent_id, branchcode ) AND NOT(parent_id IS NULL OR branchcode IS NULL); -- 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=24741 David Gustafsson <glasklas@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P5 - low |P1 - high -- 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=24741 David Gustafsson <glasklas@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P1 - high |P2 -- 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=24741 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |21674 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21674 [Bug 21674] Data integrity not enforced for library groups -- 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=24741 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@bugs.koha-c | |ommunity.org --- Comment #2 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- I tried again. For me it does not remove non-duplicate entries, but it removed an empty subgroup: Before: https://snipboard.io/20aTY9.jpg After : https://snipboard.io/lKzaeE.jpg Subgroup 'yyyy' has been removed (not correct), however 'FPL' has not been removed from the first 'xx' group. Did you notice another behavior? -- 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=24741 --- Comment #3 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- (In reply to David Gustafsson from comment #1)
I'm not 100%, but think a correct query to remove duplicates could be written like:
DELETE FROM library_groups WHERE id NOT IN ( SELECT MIN(id) FROM ( SELECT * FROM library_groups ) AS lg GROUP BY parent_id, branchcode ) AND NOT(parent_id IS NULL OR branchcode IS NULL);
This query looks correct to me. Could you submit a patch? -- 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=24741 --- Comment #4 from Stefan Berndtsson <stefan.berndtsson@ub.gu.se> --- (In reply to Jonathan Druart from comment #2)
I tried again. For me it does not remove non-duplicate entries, but it removed an empty subgroup:
Before: https://snipboard.io/20aTY9.jpg After : https://snipboard.io/lKzaeE.jpg
Subgroup 'yyyy' has been removed (not correct), however 'FPL' has not been removed from the first 'xx' group.
Did you notice another behavior?
Yes. In our case we had: https://snipboard.io/cLhEY7.jpg Since I've restored the data, I don't have an after-image, but after the migration ACQ was the only one left under __SEARCH_GROUPS__. All the others had been removed, with their entire substructure. ACQ is the one with the lowest "id", and MIN(id) therefor kept that one. -- 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=24741 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |jonathan.druart@bugs.koha-c |ity.org |ommunity.org Status|NEW |ASSIGNED -- 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=24741 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 --- Comment #5 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- Created attachment 99978 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=99978&action=edit Bug 24741: (bug 21674 follow-up) Fix destructive update DB 19.12.00.017 Previous version of the SQL query did not deal correctly with subgroup. Test plan: checkout the following commit to be just before 017 commit 715da06db557edc4b1baa51cc278fdac362c01c4 Bug 22868: DBRev 19.12.00.016 reset_all # recreate the DB Create a complex tree of library groups, with several groups, subgroups, etc. When you add a new library, refresh the page to add it several time. When ready, git checkout master, restart all the things, execute the updatedatabase script, then go to the library groups page. You should see that the duplicated entries have been removed, but subgroups have not been deleted -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 Bernardo Gonzalez Kriegel <bgkriegel@gmail.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=24741 Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #99978|0 |1 is obsolete| | --- Comment #6 from Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> --- Created attachment 100041 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=100041&action=edit Bug 24741: (bug 21674 follow-up) Fix destructive update DB 19.12.00.017 Previous version of the SQL query did not deal correctly with subgroup. Test plan: checkout the following commit to be just before 017 commit 715da06db557edc4b1baa51cc278fdac362c01c4 Bug 22868: DBRev 19.12.00.016 reset_all # recreate the DB Create a complex tree of library groups, with several groups, subgroups, etc. When you add a new library, refresh the page to add it several time. When ready, git checkout master, restart all the things, execute the updatedatabase script, then go to the library groups page. You should see that the duplicated entries have been removed, but subgroups have not been deleted Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Tested with duplicated entries on groups and subgroups, going back to the right commit and doing clean install. Patch works, subgroups are preserved. No errors. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 Nick Clemens <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- 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=24741 Nick Clemens <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #100041|0 |1 is obsolete| | --- Comment #7 from Nick Clemens <nick@bywatersolutions.com> --- Created attachment 100094 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=100094&action=edit Bug 24741: (bug 21674 follow-up) Fix destructive update DB 19.12.00.017 Previous version of the SQL query did not deal correctly with subgroup. Test plan: checkout the following commit to be just before 017 commit 715da06db557edc4b1baa51cc278fdac362c01c4 Bug 22868: DBRev 19.12.00.016 reset_all # recreate the DB Create a complex tree of library groups, with several groups, subgroups, etc. When you add a new library, refresh the page to add it several time. When ready, git checkout master, restart all the things, execute the updatedatabase script, then go to the library groups page. You should see that the duplicated entries have been removed, but subgroups have not been deleted Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Tested with duplicated entries on groups and subgroups, going back to the right commit and doing clean install. Patch works, subgroups are preserved. No errors. Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version(s)| |20.05.00 released in| | Status|Passed QA |Pushed to master -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 --- Comment #8 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- Nice work everyone! Pushed to master for 20.05 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24741 Bug 24741 depends on bug 21674, which changed state. Bug 21674 Summary: Data integrity not enforced for library groups https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21674 What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to master |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org