diff --git a/package.json b/package.json index b3a1be3b58..261821a9fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redash-client", - "version": "23.11.0-dev", + "version": "24.01.0-dev", "description": "The frontend part of Redash.", "main": "index.js", "scripts": { diff --git a/pyproject.toml b/pyproject.toml index 159a97e362..28de51b2dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ force-exclude = ''' [tool.poetry] name = "redash" -version = "23.11.0-dev" +version = "24.01.0-dev" description = "Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data." authors = ["Arik Fraimovich "] # to be added to/removed from the mailing list, please reach out to Arik via the above email or Discord diff --git a/redash/__init__.py b/redash/__init__.py index 3f7737123f..bcb1f184bd 100644 --- a/redash/__init__.py +++ b/redash/__init__.py @@ -14,7 +14,7 @@ from redash.destinations import import_destinations from redash.query_runner import import_query_runners -__version__ = "23.11.0-dev" +__version__ = "24.01.0-dev" if os.environ.get("REMOTE_DEBUG"): diff --git a/redash/models/__init__.py b/redash/models/__init__.py index ead454bbd7..a3e594b7d3 100644 --- a/redash/models/__init__.py +++ b/redash/models/__init__.py @@ -810,6 +810,18 @@ def lowercase_name(cls): def parameters(self): return self.options.get("parameters", []) + @property + def default_parameters_query_text(self): + if any(self.parameters_dict): + return self.parameterized.apply(self.parameters_dict).query + else: + return self.query_text + + @property + def parameters_dict(self): + # ignore the parameter if no default value is set + return {p["name"]: p.get("value") for p in self.parameters if p.get("value")} + @property def parameterized(self): return ParameterizedQuery(self.query_text, self.parameters, self.org) @@ -831,7 +843,7 @@ def dashboard_api_keys(self): def update_query_hash(self): should_apply_auto_limit = self.options.get("apply_auto_limit", False) if self.options else False query_runner = self.data_source.query_runner if self.data_source else BaseQueryRunner({}) - self.query_hash = query_runner.gen_query_hash(self.query_text, should_apply_auto_limit) + self.query_hash = query_runner.gen_query_hash(self.default_parameters_query_text, should_apply_auto_limit) @listens_for(Query, "before_insert") diff --git a/redash/tasks/queries/maintenance.py b/redash/tasks/queries/maintenance.py index bbfebd053f..aab077dc15 100644 --- a/redash/tasks/queries/maintenance.py +++ b/redash/tasks/queries/maintenance.py @@ -52,23 +52,18 @@ def _should_refresh_query(query): def _apply_default_parameters(query): - parameters = {p["name"]: p.get("value") for p in query.parameters} - if any(parameters): - try: - return query.parameterized.apply(parameters).query - except InvalidParameterError as e: - error = f"Skipping refresh of {query.id} because of invalid parameters: {str(e)}" - track_failure(query, error) - raise - except QueryDetachedFromDataSourceError as e: - error = ( - f"Skipping refresh of {query.id} because a related dropdown " - f"query ({e.query_id}) is unattached to any datasource." - ) - track_failure(query, error) - raise - else: - return query.query_text + try: + return query.default_parameters_query_text + except InvalidParameterError as e: + error = "Skipping refresh of {} because of invalid parameters: {}".format(query.id, str(e)) + track_failure(query, error) + raise + except QueryDetachedFromDataSourceError as e: + error = ( + "Skipping refresh of {} because a related dropdown " "query ({}) is unattached to any datasource." + ).format(query.id, e.query_id) + track_failure(query, error) + raise class RefreshQueriesError(Exception):