Spaces:
Sleeping
Sleeping
Fix db inventory regression: add name-only third fallback
Browse filesWhen both table_statistics join and pg_class return all-NULL row_counts,
the notna() guards caused the function to return an empty DataFrame,
triggering the "Could not read table inventory" error. Add a final-resort
query using crdb_internal.tables.estimated_row_count with no notna() guard
so table names always render even when counts are NULL.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- visualization/debug_page.py +20 -1
visualization/debug_page.py
CHANGED
|
@@ -102,7 +102,8 @@ _LADDER_TB2P_FIELDS = [
|
|
| 102 |
def _query_db_inventory(conn) -> pd.DataFrame:
|
| 103 |
"""
|
| 104 |
List all tables in the public schema with estimated row counts.
|
| 105 |
-
Uses CockroachDB auto-stats (table_statistics join) with pg_class fallback
|
|
|
|
| 106 |
Returns DataFrame with columns [table_name, row_count], sorted by table_name.
|
| 107 |
"""
|
| 108 |
from sqlalchemy import text as _t
|
|
@@ -153,6 +154,24 @@ def _query_db_inventory(conn) -> pd.DataFrame:
|
|
| 153 |
except Exception:
|
| 154 |
pass
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
return pd.DataFrame(columns=["table_name", "row_count"])
|
| 157 |
|
| 158 |
|
|
|
|
| 102 |
def _query_db_inventory(conn) -> pd.DataFrame:
|
| 103 |
"""
|
| 104 |
List all tables in the public schema with estimated row counts.
|
| 105 |
+
Uses CockroachDB auto-stats (table_statistics join) with pg_class fallback,
|
| 106 |
+
and a final-resort name-only fallback so the table always renders.
|
| 107 |
Returns DataFrame with columns [table_name, row_count], sorted by table_name.
|
| 108 |
"""
|
| 109 |
from sqlalchemy import text as _t
|
|
|
|
| 154 |
except Exception:
|
| 155 |
pass
|
| 156 |
|
| 157 |
+
# Final resort: table names only, row_count will be NULL — better than empty
|
| 158 |
+
try:
|
| 159 |
+
df = pd.read_sql(
|
| 160 |
+
_t("""
|
| 161 |
+
SELECT name AS table_name,
|
| 162 |
+
estimated_row_count AS row_count
|
| 163 |
+
FROM crdb_internal.tables
|
| 164 |
+
WHERE schema_name = 'public'
|
| 165 |
+
AND table_type = 'table'
|
| 166 |
+
ORDER BY name
|
| 167 |
+
"""),
|
| 168 |
+
conn,
|
| 169 |
+
)
|
| 170 |
+
if not df.empty:
|
| 171 |
+
return df
|
| 172 |
+
except Exception:
|
| 173 |
+
pass
|
| 174 |
+
|
| 175 |
return pd.DataFrame(columns=["table_name", "row_count"])
|
| 176 |
|
| 177 |
|