From 8a5338760b3f38ec7fd13918af5effe7dd81d99d Mon Sep 17 00:00:00 2001 From: "J.C. Zhong" Date: Fri, 23 Aug 2024 11:16:42 -0700 Subject: [PATCH] fix: str_to_bool and sql-limiter (#1489) * fix: str_to_bool and sql-limiter * comments --- querybook/server/lib/utils/utils.py | 7 +++++-- querybook/webapp/lib/sql-helper/sql-limiter.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/querybook/server/lib/utils/utils.py b/querybook/server/lib/utils/utils.py index dad878ba2..5206c23ca 100644 --- a/querybook/server/lib/utils/utils.py +++ b/querybook/server/lib/utils/utils.py @@ -162,5 +162,8 @@ def get_default_args(func): } -def str_to_bool(value: Union[str, bool]): - return value.lower() in (True, "yes", "true", "t", "1") +def str_to_bool(value: Optional[str]) -> bool: + if value is None: + return False + + return value.lower() in ("yes", "true", "t", "1") diff --git a/querybook/webapp/lib/sql-helper/sql-limiter.ts b/querybook/webapp/lib/sql-helper/sql-limiter.ts index 34a87df43..2cb26fb13 100644 --- a/querybook/webapp/lib/sql-helper/sql-limiter.ts +++ b/querybook/webapp/lib/sql-helper/sql-limiter.ts @@ -25,7 +25,7 @@ export function getSelectStatementLimit( language?: string ): Nullable { const tokens = tokenize(statement, { language }); - const parsedStatement = simpleParse(tokens)[0]; + const parsedStatement = simpleParse(tokens)?.[0] ?? []; // Strip nested statements out of the query const outerStatement: IToken[] = [];