villebro commented on a change in pull request #14765:
URL: https://github.com/apache/superset/pull/14765#discussion_r640509399



##########
File path: superset/views/utils.py
##########
@@ -196,6 +199,26 @@ def get_form_data(  # pylint: disable=too-many-locals
     return form_data, slc
 
 
+def add_sqllab_custom_filters(form_data: Dict[Any, Any]) -> Any:
+    """
+    SQLLab can include a "filters" attribute in the templateParams.
+    The filters attribute is a list of filters to include in the
+    request. Useful for testing templates in SQLLab.
+    """
+    try:
+        data = json.loads(request.data)
+        if isinstance(data, dict):
+            params_str = data.get("templateParams")
+            if isinstance(params_str, str):
+                params = json.loads(params_str)
+                if isinstance(params, dict):
+                    filters = params.get("filters")
+                    if filters:
+                        form_data.update({"filters": filters})
+    except (TypeError, json.JSONDecodeError):
+        data = {}

Review comment:
       I wonder if we should make `filters` a reserved keyword in template 
params and not persist that in the virtual dataset metadata? Similarly, we 
probably want to make sure any other Jinja context predefined functions 
(`filter_values` etc) or others defined in `JINJA_CONTEXT_ADDONS` are also not 
overridden. Any thoughts on this?

##########
File path: superset/views/utils.py
##########
@@ -127,13 +127,16 @@ def loads_request_json(request_json_data: str) -> 
Dict[Any, Any]:
 def get_form_data(  # pylint: disable=too-many-locals
     slice_id: Optional[int] = None, use_slice_data: bool = False
 ) -> Tuple[Dict[str, Any], Optional[Slice]]:
-    form_data = {}
+    form_data: Dict[Any, Any] = {}

Review comment:
       nit: `form_data` is `Dict[str, Any]`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to