From 0100a8e0b255737330f1b5f5c45a5e0f154cacd6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:30:39 +0000 Subject: [PATCH 1/3] Snapshot: 24.08.0-dev --- package.json | 2 +- pyproject.toml | 2 +- redash/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 06422d1d68..b5d5e9443c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redash-client", - "version": "24.07.0-dev", + "version": "24.08.0-dev", "description": "The frontend part of Redash.", "main": "index.js", "scripts": { diff --git a/pyproject.toml b/pyproject.toml index 74d1ad7435..97df8d94b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ force-exclude = ''' [tool.poetry] name = "redash" -version = "24.07.0-dev" +version = "24.08.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 16ebb66f91..58027b050e 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__ = "24.07.0-dev" +__version__ = "24.08.0-dev" if os.environ.get("REMOTE_DEBUG"): From 00c85bd35f5b1977e91a2132d8f89b46d6db7375 Mon Sep 17 00:00:00 2001 From: zachliu Date: Mon, 12 Aug 2024 13:44:38 -0400 Subject: [PATCH 2/3] add an env var to ctrl sort columns or not --- redash/models/__init__.py | 18 ++++++++++++------ redash/settings/__init__.py | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/redash/models/__init__.py b/redash/models/__init__.py index ce3446c916..17b7842da6 100644 --- a/redash/models/__init__.py +++ b/redash/models/__init__.py @@ -216,7 +216,7 @@ def get_schema(self, refresh=False): schema = query_runner.get_schema(get_stats=refresh) try: - out_schema = self._sort_schema(schema) + out_schema = self._sort_schema(schema, settings.SCHEMAS_SORT_COLUMNS) except Exception: logging.exception("Error sorting schema columns for data_source {}".format(self.id)) out_schema = schema @@ -226,11 +226,17 @@ def get_schema(self, refresh=False): return out_schema - def _sort_schema(self, schema): - return [ - {"name": i["name"], "columns": sorted(i["columns"], key=lambda x: x["name"] if isinstance(x, dict) else x)} - for i in sorted(schema, key=lambda x: x["name"]) - ] + def _sort_schema(self, schema, sort_columns=True): + if sort_columns: + return [ + { + "name": i["name"], + "columns": sorted(i["columns"], key=lambda x: x["name"] if isinstance(x, dict) else x), + } + for i in sorted(schema, key=lambda x: x["name"]) + ] + else: + return sorted(schema, key=lambda x: x["name"]) @property def _schema_key(self): diff --git a/redash/settings/__init__.py b/redash/settings/__init__.py index 75c438cff2..3e4399add5 100644 --- a/redash/settings/__init__.py +++ b/redash/settings/__init__.py @@ -49,6 +49,7 @@ # default set query results expired ttl 86400 seconds QUERY_RESULTS_EXPIRED_TTL = int(os.environ.get("REDASH_QUERY_RESULTS_EXPIRED_TTL", "86400")) +SCHEMAS_SORT_COLUMNS = parse_boolean(os.environ.get("REDASH_SCHEMAS_SORT_COLUMNS", "true")) SCHEMAS_REFRESH_SCHEDULE = int(os.environ.get("REDASH_SCHEMAS_REFRESH_SCHEDULE", 30)) AUTH_TYPE = os.environ.get("REDASH_AUTH_TYPE", "api_key") From e1745018c00e03eb5a4de6218f28b6bd95687f25 Mon Sep 17 00:00:00 2001 From: zachliu Date: Mon, 12 Aug 2024 13:45:16 -0400 Subject: [PATCH 3/3] add a test --- tests/models/test_data_sources.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/models/test_data_sources.py b/tests/models/test_data_sources.py index 7db4d463a3..7be96870dd 100644 --- a/tests/models/test_data_sources.py +++ b/tests/models/test_data_sources.py @@ -58,7 +58,28 @@ def test_schema_sorter(self): {"name": "zoo", "columns": ["is_cow", "is_snake", "is_zebra"]}, ] - real_output = self.factory.data_source._sort_schema(input_data) + real_output = self.factory.data_source._sort_schema(input_data, sort_columns=True) + + self.assertEqual(real_output, expected_output) + + def test_schema_sorter_columns_unsorted(self): + input_data = [ + {"name": "zoo", "columns": ["is_zebra", "is_snake", "is_cow"]}, + { + "name": "all_terain_vehicle", + "columns": ["has_wheels", "has_engine", "has_all_wheel_drive"], + }, + ] + + expected_output = [ + { + "name": "all_terain_vehicle", + "columns": ["has_wheels", "has_engine", "has_all_wheel_drive"], + }, + {"name": "zoo", "columns": ["is_zebra", "is_snake", "is_cow"]}, + ] + + real_output = self.factory.data_source._sort_schema(input_data, sort_columns=False) self.assertEqual(real_output, expected_output)