Skip to content

Commit 9845c26

Browse files
Use updated CanvasBuilder, revert type checking workaround for verify (#19)
* revert type checking workaround for Headers * bump SDK to 1.21.1 * use CanvasBuilder for notebook canvas updates
1 parent 53875e0 commit 9845c26

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

examples/chem-sync-local-flask/local_app/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def receive_webhooks(target: str) -> tuple[str, int]: # noqa: ARG001
2525

2626
# Important! To verify webhooks, we need to pass the body as an unmodified string
2727
# Flask's request.data is bytes, so decode to string. Passing bytes or JSON won't work
28-
verify(app_def_id, request.data.decode("utf-8"), request.headers) # type: ignore[arg-type]
28+
verify(app_def_id, request.data.decode("utf-8"), request.headers)
2929

3030
logger.debug("Received webhook message: %s", request.json)
3131
# Dispatch work and ACK webhook as quickly as possible

examples/chem-sync-local-flask/local_app/benchling_app/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def handle_webhook(webhook_dict: dict[str, Any]) -> None:
3636
elif isinstance(webhook.message, CanvasInteractionWebhookV2):
3737
route_interaction_webhook(app, webhook.message)
3838
elif isinstance(webhook.message, CanvasCreatedWebhookV2Beta):
39-
render_search_canvas_for_created_canvas(app, webhook.message.canvas_id)
39+
render_search_canvas_for_created_canvas(app, webhook.message)
4040
else:
4141
# Should only happen if the app's manifest requests webhooks that aren't handled in its code paths
4242
raise UnsupportedWebhookError(f"Received an unsupported webhook type: {webhook}")

examples/chem-sync-local-flask/local_app/benchling_app/views/canvas_initialize.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
TextInputUiBlock,
1010
TextInputUiBlockType,
1111
)
12-
from benchling_sdk.models.webhooks.v0 import CanvasInitializeWebhookV2
12+
from benchling_sdk.models.webhooks.v0 import (
13+
CanvasCreatedWebhookV2Beta,
14+
CanvasInitializeWebhookV2,
15+
)
1316

1417
from local_app.benchling_app.views.constants import SEARCH_BUTTON_ID, SEARCH_TEXT_ID
1518

1619

17-
def _canvas_builder_from_canvas_id(app: App, canvas_id: str) -> CanvasBuilder:
18-
current_canvas = app.benchling.apps.get_canvas_by_id(canvas_id)
19-
return CanvasBuilder.from_canvas(current_canvas)
20-
2120
def render_search_canvas(app: App, canvas_initialized: CanvasInitializeWebhookV2) -> None:
2221
with app.create_session_context("Show Sync Search", timeout_seconds=20):
2322
canvas_builder = CanvasBuilder(
@@ -29,11 +28,11 @@ def render_search_canvas(app: App, canvas_initialized: CanvasInitializeWebhookV2
2928
app.benchling.apps.create_canvas(canvas_builder.to_create())
3029

3130

32-
def render_search_canvas_for_created_canvas(app: App, canvas_id: str) -> None:
31+
def render_search_canvas_for_created_canvas(app: App, canvas_created: CanvasCreatedWebhookV2Beta) -> None:
3332
with app.create_session_context("Show Sync Search", timeout_seconds=20):
34-
canvas_builder = _canvas_builder_from_canvas_id(app, canvas_id)
33+
canvas_builder = CanvasBuilder(app_id=app.id, feature_id=canvas_created.feature_id)
3534
canvas_builder.blocks.append(input_blocks())
36-
app.benchling.apps.update_canvas(canvas_id, canvas_builder.to_update())
35+
app.benchling.apps.update_canvas(canvas_created.canvas_id, canvas_builder.to_update())
3736

3837

3938
def input_blocks() -> list[UiBlock]:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
flask~=3.0.2
22
# Cryptography extra needed for webhook verification
3-
benchling-sdk[cryptography]==1.19.0
3+
benchling-sdk[cryptography]==1.21.1

0 commit comments

Comments
 (0)