LP#1781480: Closures remeber values in subtle ways...
authorMike Rylander <mrylander@gmail.com>
Mon, 17 Sep 2018 15:33:29 +0000 (11:33 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 21 Sep 2018 14:28:59 +0000 (10:28 -0400)
... and we must take care to avoid that.  This commit forces a state variable
to be statically assigned an empty list rather than depending on the idiomatic
undef to vivicate an empty list.  This is important for all OpenSRF methods,
and manifests here as a search "remembering" a previously chosen location
group.  A comment to that point is included for our future selves.

The core probably arises from the fact that, in the end, OpenSRF methods are
generated closures.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jeanette Lundgren <jlundgren@cwmars.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm

index 506846a..828304f 100644 (file)
@@ -451,7 +451,9 @@ sub biblio_multi_search_full_rec {
     my $cl_table = asset::copy_location->table;
     my $br_table = biblio::record_entry->table;
 
-    my $cj = 'HAVING COUNT(x.record) = ' . scalar(@selects) if ($class_join eq 'AND');
+    my $cj = undef;
+    $cj = 'HAVING COUNT(x.record) = ' . scalar(@selects) if ($class_join eq 'AND');
+
     my $search_table =
         '(SELECT x.record, sum(x.sum) FROM (('.
             join(') UNION ALL (', @selects).
@@ -3057,7 +3059,8 @@ sub query_parser_fts {
 
     # gather location_groups
     if (my ($filter) = $query->parse_tree->find_filter('location_groups')) {
-        my @loc_groups = @{$filter->args} if (@{$filter->args});
+        my @loc_groups = ();
+        @loc_groups = @{$filter->args} if (@{$filter->args});
         
         # collect the mapped locations and add them to the locations() filter
         if (@loc_groups) {
@@ -3227,7 +3230,11 @@ sub query_parser_fts_wrapper {
         # explicitly supplied one
         my $site = undef;
 
-        my @lg_id_list = @{$args{location_groups}} if (ref $args{location_groups});
+        my @lg_id_list = (); # We must define the variable with a static value
+                             # because an idomatic my+set causes the previous
+                             # value is remembered via closure.  
+
+        @lg_id_list = @{$args{location_groups}} if (ref $args{location_groups});
 
         my ($lg_filter) = $base_plan->parse_tree->find_filter('location_groups');
         @lg_id_list = @{$lg_filter->args} if ($lg_filter && @{$lg_filter->args});