LP#1886852: Protect against dupes in hold-copy map function
authorMike Rylander <mrylander@gmail.com>
Wed, 8 Jul 2020 17:18:52 +0000 (13:18 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 17 Jul 2020 11:07:22 +0000 (07:07 -0400)
If the DB function that regenerates the hold-copy maps for a hold
receives duplicate copies in its second parameter, it blows up.  This
commit prevents that by making the list unique at use time.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.function.distinct-regen_copy_map.sql [new file with mode: 0755]

index af8a3e3..8d8163b 100644 (file)
@@ -548,7 +548,7 @@ CREATE OR REPLACE FUNCTION
     action.hold_request_regen_copy_maps(
         hold_id INTEGER, copy_ids INTEGER[]) RETURNS VOID AS $$
     DELETE FROM action.hold_copy_map WHERE hold = $1;
-    INSERT INTO action.hold_copy_map (hold, target_copy) SELECT $1, UNNEST($2);
+    INSERT INTO action.hold_copy_map (hold, target_copy) SELECT DISTINCT $1, UNNEST($2);
 $$ LANGUAGE SQL;
 
 CREATE TABLE action.transit_copy (
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.distinct-regen_copy_map.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.distinct-regen_copy_map.sql
new file mode 100755 (executable)
index 0000000..2d4739a
--- /dev/null
@@ -0,0 +1,12 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION
+    action.hold_request_regen_copy_maps(
+        hold_id INTEGER, copy_ids INTEGER[]) RETURNS VOID AS $$
+    DELETE FROM action.hold_copy_map WHERE hold = $1;
+    INSERT INTO action.hold_copy_map (hold, target_copy) SELECT DISTINCT $1, UNNEST($2);
+$$ LANGUAGE SQL;
+
+COMMIT;