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

amitmiran pushed a commit to branch 1.2
in repository https://gitbox.apache.org/repos/asf/superset.git

commit f8491dfc0a2b5dae1674afc2488c50e4362135b0
Author: Ville Brofeldt <[email protected]>
AuthorDate: Wed May 5 13:52:17 2021 +0300

    fix(annotations): pass force param to annotation request (#14483)
    
    * fix(annotations): pass force param to annotation request
    
    * use strtobool
    
    * add util for parsing bools
    
    (cherry picked from commit 93c7f5bb446ec6895d7702835f3157426955d5a9)
---
 superset-frontend/src/chart/chartAction.js         | 17 ++++++++++--
 .../src/explore/exploreUtils/index.js              |  3 +-
 superset/utils/core.py                             | 32 ++++++++++++++++++++++
 superset/views/core.py                             |  4 ++-
 4 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/superset-frontend/src/chart/chartAction.js 
b/superset-frontend/src/chart/chartAction.js
index 5e5fc46..9be1b6a 100644
--- a/superset-frontend/src/chart/chartAction.js
+++ b/superset-frontend/src/chart/chartAction.js
@@ -248,6 +248,7 @@ export function runAnnotationQuery(
   formData = null,
   key,
   isDashboardRequest = false,
+  force = false,
 ) {
   return function (dispatch, getState) {
     const sliceKey = key || Object.keys(getState().charts)[0];
@@ -286,7 +287,12 @@ export function runAnnotationQuery(
     }
 
     const isNative = annotation.sourceType === ANNOTATION_SOURCE_TYPES.NATIVE;
-    const url = getAnnotationJsonUrl(annotation.value, sliceFormData, 
isNative);
+    const url = getAnnotationJsonUrl(
+      annotation.value,
+      sliceFormData,
+      isNative,
+      force,
+    );
     const controller = new AbortController();
     const { signal } = controller;
 
@@ -462,7 +468,14 @@ export function exploreJSON(
       dispatch(updateQueryFormData(formData, key)),
       ...annotationLayers.map(x =>
         dispatch(
-          runAnnotationQuery(x, timeout, formData, key, isDashboardRequest),
+          runAnnotationQuery(
+            x,
+            timeout,
+            formData,
+            key,
+            isDashboardRequest,
+            force,
+          ),
         ),
       ),
     ]);
diff --git a/superset-frontend/src/explore/exploreUtils/index.js 
b/superset-frontend/src/explore/exploreUtils/index.js
index 12a70d3..f1ddd17 100644
--- a/superset-frontend/src/explore/exploreUtils/index.js
+++ b/superset-frontend/src/explore/exploreUtils/index.js
@@ -57,7 +57,7 @@ export function getHostName(allowDomainSharding = false) {
   return availableDomains[currentIndex];
 }
 
-export function getAnnotationJsonUrl(slice_id, form_data, isNative) {
+export function getAnnotationJsonUrl(slice_id, form_data, isNative, force) {
   if (slice_id === null || slice_id === undefined) {
     return null;
   }
@@ -69,6 +69,7 @@ export function getAnnotationJsonUrl(slice_id, form_data, 
isNative) {
       form_data: safeStringify(form_data, (key, value) =>
         value === null ? undefined : value,
       ),
+      force,
     })
     .toString();
 }
diff --git a/superset/utils/core.py b/superset/utils/core.py
index 797bac5..1a711ec 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -1681,3 +1681,35 @@ def normalize_dttm_col(
         df[DTTM_ALIAS] += timedelta(hours=offset)
     if time_shift is not None:
         df[DTTM_ALIAS] += time_shift
+
+
+def parse_boolean_string(bool_str: Optional[str]) -> bool:
+    """
+    Convert a string representation of a true/false value into a boolean
+
+    >>> parse_boolean_string(None)
+    False
+    >>> parse_boolean_string('false')
+    False
+    >>> parse_boolean_string('true')
+    True
+    >>> parse_boolean_string('False')
+    False
+    >>> parse_boolean_string('True')
+    True
+    >>> parse_boolean_string('foo')
+    False
+    >>> parse_boolean_string('0')
+    False
+    >>> parse_boolean_string('1')
+    True
+
+    :param bool_str: string representation of a value that is assumed to be 
boolean
+    :return: parsed boolean value
+    """
+    if bool_str is None:
+        return False
+    try:
+        return bool(strtobool(bool_str.lower()))
+    except ValueError:
+        return False
diff --git a/superset/views/core.py b/superset/views/core.py
index 7fb2f47..06c03aa 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -481,6 +481,8 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
         self, layer_id: int
     ) -> FlaskResponse:
         form_data = get_form_data()[0]
+        force = utils.parse_boolean_string(request.args.get("force"))
+
         form_data["layer_id"] = layer_id
         form_data["filters"] = [{"col": "layer_id", "op": "==", "val": 
layer_id}]
         # Set all_columns to ensure the TableViz returns the necessary columns 
to the
@@ -499,7 +501,7 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
             "changed_by_fk",
         ]
         datasource = AnnotationDatasource()
-        viz_obj = viz.viz_types["table"](datasource, form_data=form_data, 
force=False)
+        viz_obj = viz.viz_types["table"](datasource, form_data=form_data, 
force=force)
         payload = viz_obj.get_payload()
         return 
data_payload_response(*viz_obj.payload_json_and_has_error(payload))
 

Reply via email to