You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2020/10/28 08:30:56 UTC
[incubator-superset] 02/08: fix: disable jinja2 SQL templating
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch 0.38
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 922b8aa7c9f541fd93943af0f3ed7e8186134bf0
Author: Daniel Gaspar <da...@gmail.com>
AuthorDate: Thu Sep 17 16:13:47 2020 +0100
fix: disable jinja2 SQL templating
# Conflicts:
# superset/config.py
---
superset/config.py | 1 +
superset/jinja_context.py | 21 +++++++++++++++++----
tests/superset_test_config.py | 7 ++++++-
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/superset/config.py b/superset/config.py
index 71c1e99..52566af 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -298,6 +298,7 @@ DEFAULT_FEATURE_FLAGS: Dict[str, bool] = {
"CLIENT_CACHE": False,
"ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False,
"ENABLE_DASHBOARD_ETAG_HEADER": False,
+ "ENABLE_TEMPLATE_PROCESSING": False,
"KV_STORE": False,
"PRESTO_EXPAND_DATA": False,
# Exposes API endpoint to compute thumbnails
diff --git a/superset/jinja_context.py b/superset/jinja_context.py
index bc35dbe..988aea8 100644
--- a/superset/jinja_context.py
+++ b/superset/jinja_context.py
@@ -23,7 +23,7 @@ from flask import g, request
from jinja2.sandbox import SandboxedEnvironment
from superset import jinja_base_context
-from superset.extensions import jinja_context_manager
+from superset.extensions import feature_flag_manager, jinja_context_manager
from superset.utils.core import convert_legacy_filters_into_adhoc, merge_extra_filters
if TYPE_CHECKING:
@@ -247,6 +247,16 @@ class BaseTemplateProcessor: # pylint: disable=too-few-public-methods
return template.render(kwargs)
+class NoOpTemplateProcessor(
+ BaseTemplateProcessor
+): # pylint: disable=too-few-public-methods
+ def process_template(self, sql: str, **kwargs: Any) -> str:
+ """
+ Makes processing a template a noop
+ """
+ return sql
+
+
class PrestoTemplateProcessor(BaseTemplateProcessor):
"""Presto Jinja context
@@ -324,7 +334,10 @@ def get_template_processor(
query: Optional["Query"] = None,
**kwargs: Any,
) -> BaseTemplateProcessor:
- template_processor = template_processors.get(
- database.backend, BaseTemplateProcessor
- )
+ if feature_flag_manager.is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
+ template_processor = template_processors.get(
+ database.backend, BaseTemplateProcessor
+ )
+ else:
+ template_processor = NoOpTemplateProcessor
return template_processor(database=database, table=table, query=query, **kwargs)
diff --git a/tests/superset_test_config.py b/tests/superset_test_config.py
index 513d3d9..8d03115 100644
--- a/tests/superset_test_config.py
+++ b/tests/superset_test_config.py
@@ -49,7 +49,12 @@ HIVE_POLL_INTERVAL = 0.1
SQL_MAX_ROW = 666
SQLLAB_CTAS_NO_LIMIT = True # SQL_MAX_ROW will not take affect for the CTA queries
-FEATURE_FLAGS = {"foo": "bar", "KV_STORE": True, "SHARE_QUERIES_VIA_KV_STORE": True}
+FEATURE_FLAGS = {
+ "foo": "bar",
+ "KV_STORE": True,
+ "SHARE_QUERIES_VIA_KV_STORE": True,
+ "ENABLE_TEMPLATE_PROCESSING": True,
+}
def GET_FEATURE_FLAGS_FUNC(ff):