Skip to content

Commit

Permalink
Allow LIMIT to be specified in parameters (#7052)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored and xtinec committed Mar 20, 2019
1 parent 6d0c390 commit 0e1a3d3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,10 +2531,8 @@ def sql_json(self):
)

client_id = request.form.get('client_id') or utils.shortid()[:10]
limits = [mydb.db_engine_spec.get_limit_from_sql(sql), limit]
query = Query(
database_id=int(database_id),
limit=min(lim for lim in limits if lim is not None),
sql=sql,
schema=schema,
select_as_cta=request.form.get('select_as_cta') == 'true',
Expand Down Expand Up @@ -2564,6 +2562,10 @@ def sql_json(self):
return json_error_response(
'Template rendering failed: {}'.format(utils.error_msg_from_exception(e)))

# set LIMIT after template processing
limits = [mydb.db_engine_spec.get_limit_from_sql(rendered_query), limit]
query.limit = min(lim for lim in limits if lim is not None)

# Async request.
if async_:
logging.info('Running query on a Celery worker')
Expand Down

0 comments on commit 0e1a3d3

Please sign in to comment.