You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2021/11/30 18:19:01 UTC

[lucene-solr] branch branch_8_11 updated: SOLR-15813: Schema designer not handling stored as a string (vs. boolean) in the config overlay (#435) (#2618)

This is an automated email from the ASF dual-hosted git repository.

thelabdude pushed a commit to branch branch_8_11
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8_11 by this push:
     new b09ac5b  SOLR-15813: Schema designer not handling  stored as a string (vs. boolean) in the config overlay (#435) (#2618)
b09ac5b is described below

commit b09ac5bbce57dbb2c5916cad3215dcef66157a64
Author: Timothy Potter <th...@gmail.com>
AuthorDate: Tue Nov 30 11:17:35 2021 -0700

    SOLR-15813: Schema designer not handling  stored as a string (vs. boolean) in the config overlay (#435) (#2618)
---
 solr/CHANGES.txt                                       |  2 ++
 .../solr/handler/designer/SchemaDesignerSettings.java  | 18 ++++++++++++++----
 .../handler/designer/SchemaDesignerSettingsDAO.java    | 11 ++---------
 .../designer/TestSchemaDesignerSettingsDAO.java        |  5 +++++
 .../web/js/angular/controllers/schema-designer.js      | 10 +++++-----
 5 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f2bf6f2..69bdb5f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -23,6 +23,8 @@ Bug Fixes
 
 * SOLR-15794: Switching a PRS collection from true -> false -> true results in INACTIVE replicas (noble)
 
+* SOLR-15813: Schema designer not handling `update.autoCreateFields` stored as a string (vs. boolean) in the config overlay (Timothy Potter)
+
 ==================  8.11.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java
index 756a26d..b567d5e 100644
--- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java
+++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettings.java
@@ -39,13 +39,23 @@ class SchemaDesignerSettings implements SchemaDesignerConstants {
 
   @SuppressWarnings("unchecked")
   SchemaDesignerSettings(Map<String, Object> stored) {
-    this.isDisabled = (Boolean) stored.getOrDefault(DESIGNER_KEY + DISABLED, false);
+    this.isDisabled = getSettingAsBool(stored, DESIGNER_KEY + DISABLED, false);
     this.publishedVersion = null;
     this.copyFrom = (String) stored.get(DESIGNER_KEY + COPY_FROM_PARAM);
     this.languages = (List<String>) stored.getOrDefault(DESIGNER_KEY + LANGUAGES_PARAM, Collections.emptyList());
-    this.dynamicFieldsEnabled = (Boolean) stored.getOrDefault(DESIGNER_KEY + ENABLE_DYNAMIC_FIELDS_PARAM, true);
-    this.nestedDocsEnabled = (Boolean) stored.getOrDefault(DESIGNER_KEY + ENABLE_NESTED_DOCS_PARAM, false);
-    this.fieldGuessingEnabled = (Boolean) stored.getOrDefault(AUTO_CREATE_FIELDS, true);
+    this.dynamicFieldsEnabled = getSettingAsBool(stored, DESIGNER_KEY + ENABLE_DYNAMIC_FIELDS_PARAM, true);
+    this.nestedDocsEnabled = getSettingAsBool(stored, DESIGNER_KEY + ENABLE_NESTED_DOCS_PARAM, false);
+    this.fieldGuessingEnabled = getSettingAsBool(stored, AUTO_CREATE_FIELDS, true);
+  }
+
+  static boolean getSettingAsBool(final Map<String, Object> stored, final String key, final boolean defaultValue) {
+    boolean settingAsBool = defaultValue;
+    final Object settingValue = stored != null ? stored.get(key) : null;
+    if (settingValue != null) {
+      // covers either a Boolean or String object in the map
+      settingAsBool = Boolean.parseBoolean(settingValue.toString());
+    }
+    return settingAsBool;
   }
 
   Map<String, Object> toMap() {
diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java
index 38efdf4..90373e2 100644
--- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java
+++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java
@@ -114,7 +114,7 @@ class SchemaDesignerSettingsDAO implements SchemaDesignerConstants {
       log.error("Failed to get config overlay for {}", configSet, exc);
     }
     Map<String, Object> userProps = overlay != null ? overlay.getUserProps() : Collections.emptyMap();
-    return (boolean) userProps.getOrDefault(DESIGNER_KEY + DISABLED, false);
+    return SchemaDesignerSettings.getSettingAsBool(userProps, DESIGNER_KEY + DISABLED, false);
   }
 
   @SuppressWarnings("unchecked")
@@ -143,15 +143,8 @@ class SchemaDesignerSettingsDAO implements SchemaDesignerConstants {
       return false; // no URP chain, so can't be enabled
     }
 
-    boolean isEnabled = true;
     ConfigOverlay overlay = solrConfig.getOverlay();
-    if (overlay != null) {
-      Map<String, Object> userProps = overlay.getUserProps();
-      if (userProps != null) {
-        isEnabled = (Boolean) userProps.getOrDefault(AUTO_CREATE_FIELDS, true);
-      }
-    }
-    return isEnabled;
+    return overlay == null || SchemaDesignerSettings.getSettingAsBool(overlay.getUserProps(), AUTO_CREATE_FIELDS, true);
   }
 
   private boolean hasFieldGuessingURPChain(final SolrConfig solrConfig) {
diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java
index 2f3a037..a0597cf 100644
--- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java
+++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerSettingsDAO.java
@@ -118,6 +118,11 @@ public class TestSchemaDesignerSettingsDAO extends SolrCloudTestCase implements
         DESIGNER_KEY + LANGUAGES_PARAM, Collections.singletonList("en"));
     assertDesignerSettings(expSettings, settings);
     assertTrue("should be disabled", dao.isDesignerDisabled(configSet));
+
+    // handles booleans stored as strings in the overlay
+    Map<String,Object> stored = Map.of(AUTO_CREATE_FIELDS, "false");
+    settings = new SchemaDesignerSettings(stored);
+    assertFalse(settings.fieldGuessingEnabled());
   }
 
   protected void assertDesignerSettings(Map<String, Object> expectedMap, SchemaDesignerSettings actual) {
diff --git a/solr/webapp/web/js/angular/controllers/schema-designer.js b/solr/webapp/web/js/angular/controllers/schema-designer.js
index 3d17036..3bd5e6c 100644
--- a/solr/webapp/web/js/angular/controllers/schema-designer.js
+++ b/solr/webapp/web/js/angular/controllers/schema-designer.js
@@ -258,7 +258,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
           $scope.sampleMessage = "Please upload or paste some sample documents to build the '" + $scope.currentSchema + "' schema.";
         }
       }
-    });
+    }, $scope.errorHandler);
   };
 
   $scope.showNewSchemaDialog = function () {
@@ -751,7 +751,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
 
       $scope.schemaDiffExists = !(diff.fields == null && diff.fieldTypes == null && dynamicFields == null && diff.copyFields == null);
       $scope.showDiff = true;
-    });
+    }, $scope.errorHandler);
   }
 
   $scope.togglePublish = function (event) {
@@ -849,7 +849,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
       if (data.analysis && data.analysis["field_names"]) {
         $scope.result = processFieldAnalysisData(data.analysis["field_names"][field]);
       }
-    });
+    }, $scope.errorHandler);
   };
 
   $scope.changeLanguages = function () {
@@ -915,7 +915,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
         $scope.showAnalysis = false;
         $scope.selectNodeInTree(id);
       }
-    });
+    }, $scope.errorHandler);
   };
   
   function fieldNodes(src, type) {
@@ -1849,7 +1849,7 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
         }
       }
       $scope.onSelectQueryResultsNode(nodeId);
-    });
+    }, $scope.errorHandler);
   };
 
   $scope.toggleShowAnalysisJson = function () {