getredash / redash

Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.
http://redash.io/
BSD 2-Clause "Simplified" License
26.49k stars 4.39k forks source link

Enhanced schema fetch is broken #5744

Open susodapop opened 2 years ago

susodapop commented 2 years ago

Issue Summary

In https://github.com/getredash/redash/pull/4595 we added logic that sorts schema tokens alphabetically. But this logic silently ignores all keys in the schema dictionary except for name and columns. However, if REDASH_SCHEMA_RUN_TABLE_SIZE_CALCULATIONS is enabled, each table will also include a size key which is now being silently dropped.

The _sort_schema() method needs to be re-written as follows:


# current version
    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"])
        ]

# fixed
    def _sort_schema(self, schema):
        return [
            {**i, "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"])
        ]

Steps to Reproduce

  1. Set REDASH_SCHEMA_RUN_TABLE_SIZE_CALCULATIONS=true
  2. Connect to postgres database
  3. Observe that row counts in each table are not displayed in the schema browser

Technical details:

MRdevX commented 4 months ago

Hi @susodapop, Is there any updates on this feature? I really like to have this sort feature on the redash. I'm using Redash version: 24.04.0-dev using Bitnami Helm Charts.