superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Fix url_param macro when param is missing (#6699)
Date Thu, 17 Jan 2019 04:44:33 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 65f7f29  Fix url_param macro when param is missing (#6699)
65f7f29 is described below

commit 65f7f2920d96de8df17d594204438e7fdaf7668d
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Jan 16 20:44:28 2019 -0800

    Fix url_param macro when param is missing (#6699)
    
    User @ravi on Slack reported issues trying to use url_param jinja macro.
    explore_json would raise a "KeyError: 'url_params'".
    
    The feature works when a parameter is passed, but fails hard when none
    are passed.
    
    I improved the docstring on the macro as well.
---
 superset/jinja_context.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/superset/jinja_context.py b/superset/jinja_context.py
index 8dd0244..5672441 100644
--- a/superset/jinja_context.py
+++ b/superset/jinja_context.py
@@ -42,7 +42,18 @@ BASE_CONTEXT.update(config.get('JINJA_CONTEXT_ADDONS', {}))
 
 
 def url_param(param, default=None):
-    """Get a url or post data parameter
+    """Read a url or post parameter and use it in your SQL Lab query
+
+    When in SQL Lab, it's possible to add arbitrary URL "query string"
+    parameters, and use those in your SQL code. For instance you can
+    alter your url and add `?foo=bar`, as in
+    `{domain}/superset/sqllab?foo=bar`. Then if your query is something like
+    SELECT * FROM foo = '{{ url_param('foo') }}', it will be parsed at
+    runtime and replaced by the value in the URL.
+
+    As you create a visualization form this SQL Lab query, you can pass
+    parameters in the explore view as well as from the dashboard, and
+    it should carry through to your queries.
 
     :param param: the parameter to lookup
     :type param: str
@@ -54,7 +65,7 @@ def url_param(param, default=None):
     # Supporting POST as well as get
     if request.form.get('form_data'):
         form_data = json.loads(request.form.get('form_data'))
-        url_params = form_data['url_params'] or {}
+        url_params = form_data.get('url_params') or {}
         return url_params.get(param, default)
     return default
 


Mime
View raw message