From 5a5ffda274e1b48f749e5b5e46f24b18f598439c Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Fri, 1 Sep 2023 18:36:46 -0400 Subject: [PATCH 1/2] Try to stabilize the snowpark odd errors * Cache the Session returned by Session.builder.create() * Properly pin snowpark to use 1.5.1 (latest in INFORMATION_SCHEMA.PACKAGES) * Use the `execute_select` variant on Connection which calls `to_pandas()` Aggressively clicking locally prior to this change, would result in an exception every ~5 page views. After this change, I've yet to get an exception on the page (one in the console, though). I'm not sure what about the non `is_select` branch is giving us grief though. rel #35 --- app/ui/connection.py | 3 +-- app/ui/reports_heatmap.py | 2 +- app/ui/reports_warehouse.py | 2 +- app/ui/setup.py | 4 ++-- pyproject.toml | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/ui/connection.py b/app/ui/connection.py index 1376e651..334fcc5a 100644 --- a/app/ui/connection.py +++ b/app/ui/connection.py @@ -83,8 +83,7 @@ def get(cls): "schema": schema, } - Session.builder.configs(connection_parameters).create() - cls.session = get_active_session() + cls.session = Session.builder.configs(connection_parameters).create() return cls.session @staticmethod diff --git a/app/ui/reports_heatmap.py b/app/ui/reports_heatmap.py index 7ccbe93b..55a2f8a9 100644 --- a/app/ui/reports_heatmap.py +++ b/app/ui/reports_heatmap.py @@ -31,7 +31,7 @@ def heatmap( high = ( bf.end - datetime.timedelta(days=bf.end.weekday()) + datetime.timedelta(days=6) ) - df = connection.execute( + df = connection.execute_select( sql, {"start": low, "end": high, "warehouse_names": bf.warehouse_names} ) df.set_index(["PERIOD"], inplace=True) diff --git a/app/ui/reports_warehouse.py b/app/ui/reports_warehouse.py index 2356abb7..2cb6ff05 100644 --- a/app/ui/reports_warehouse.py +++ b/app/ui/reports_warehouse.py @@ -147,7 +147,7 @@ def warehouse_users(container): group by warehouse_id, warehouse_name, st_period; """ - df = connection.execute( + df = connection.execute_select( sql, {"start": bf.start, "end": bf.end, "warehouse_names": bf.warehouse_names}, ) diff --git a/app/ui/setup.py b/app/ui/setup.py index 3faac2e2..f5ccd535 100644 --- a/app/ui/setup.py +++ b/app/ui/setup.py @@ -45,7 +45,7 @@ def decode_token(token: str): def setup_permissions(): - db = connection.execute("select current_database() as db").values[0][0] + db = connection.execute_select("select current_database() as db").values[0][0] privileges = [ "EXECUTE MANAGED TASK", @@ -64,7 +64,7 @@ def setup_permissions(): def setup_block(): db, account, user, sf_region, sd_deployment = list( - connection.execute( + connection.execute_select( """select current_database() as db, current_account() as account, current_user() as username, diff --git a/pyproject.toml b/pyproject.toml index 23c99e21..aba408dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ readme = "README.md" python = "~3.8" plotly = "~5.11" streamlit = "~1.22" -snowflake-snowpark-python = { version = "^1.5.1", extras = ["pandas"] } +snowflake-snowpark-python = { version = "~1.5.1", extras = ["pandas"] } [tool.poetry.group.dev.dependencies] watchdog = "^3.0.0" From 891b6d897570c7007edcf0e2e3254bb5aa184dc7 Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Sat, 2 Sep 2023 15:42:58 -0500 Subject: [PATCH 2/2] Precommit nerd --- app/ui/connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/ui/connection.py b/app/ui/connection.py index 334fcc5a..e286ebca 100644 --- a/app/ui/connection.py +++ b/app/ui/connection.py @@ -83,7 +83,9 @@ def get(cls): "schema": schema, } - cls.session = Session.builder.configs(connection_parameters).create() + cls.session = Session.builder.configs( + connection_parameters + ).create() return cls.session @staticmethod