Skip to content

Commit

Permalink
Try to stabilize the snowpark odd errors
Browse files Browse the repository at this point in the history
* 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 sundeck-io#35
  • Loading branch information
joshelser committed Sep 1, 2023
1 parent 27214f4 commit 0095e17
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app/ui/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/ui/reports_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/ui/reports_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)
Expand Down
4 changes: 2 additions & 2 deletions app/ui/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 0095e17

Please sign in to comment.