From ca33deae12738dfac14ccd6fb1d1d41b142c6504 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 17 Dec 2023 12:07:14 +0530 Subject: [PATCH] fix: cast SQL booleans to python --- frappe/commands/site.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 31a4be3340..9b8d2d9131 100644 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -593,7 +593,10 @@ def describe_database_table(context, doctype, column): def _extract_table_stats(doctype: str, columns: list[str]) -> dict: - from frappe.utils import get_table_name + from frappe.utils import cstr, get_table_name + + def sql_bool(val): + return cstr(val).lower() in ("yes", "1", "true") table = get_table_name(doctype, wrap_in_backticks=True) @@ -603,7 +606,7 @@ def _extract_table_stats(doctype: str, columns: list[str]) -> dict: { "column": field["Field"], "type": field["Type"], - "is_nullable": field["Null"], + "is_nullable": sql_bool(field["Null"]), "default": field["Default"], } ) @@ -618,11 +621,11 @@ def _extract_table_stats(doctype: str, columns: list[str]) -> dict: for idx in frappe.db.sql(f"show index from {table}", as_dict=True): indexes.append( { - "unique": not idx["Non_unique"], + "unique": not sql_bool(idx["Non_unique"]), "cardinality": idx["Cardinality"], "name": idx["Key_name"], "sequence": idx["Seq_in_index"], - "nullable": idx["Null"], + "nullable": sql_bool(idx["Null"]), "column": idx["Column_name"], "type": idx["Index_type"], }