From 30430828fc1114779bff6c2c1378ef8ac1fe9edc Mon Sep 17 00:00:00 2001 From: "J.C. Zhong" Date: Fri, 23 Aug 2024 17:50:49 +0000 Subject: [PATCH 1/2] fix: str_to_bool and sql-limiter --- querybook/server/lib/utils/utils.py | 4 ++-- querybook/webapp/lib/sql-helper/sql-limiter.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/querybook/server/lib/utils/utils.py b/querybook/server/lib/utils/utils.py index dad878ba2..bacd37c25 100644 --- a/querybook/server/lib/utils/utils.py +++ b/querybook/server/lib/utils/utils.py @@ -162,5 +162,5 @@ 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: str): + return False if value is None else 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..a18aef424 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[] = []; From 397248504e62fa67d4672e046716e456d9ee8164 Mon Sep 17 00:00:00 2001 From: "J.C. Zhong" Date: Fri, 23 Aug 2024 18:00:46 +0000 Subject: [PATCH 2/2] 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 bacd37c25..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: str): - return False if value is None else value.lower() in ("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 a18aef424..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[] = [];