Skip to content

Fix KeyError('event_name') in DataBlock.process_events for control-only events - #2095

Open
jrneilson wants to merge 1 commit into
datalab-org:mainfrom
jrneilson:fix/insitu-block-process-events-keyerror
Open

jrneilson wants to merge 1 commit into
datalab-org:mainfrom
jrneilson:fix/insitu-block-process-events-keyerror

Conversation

@jrneilson

Copy link
Copy Markdown

In-situ XRD/NMR/UVVis blocks trigger their async processing step by sending a bare
{"trigger_async": true} event (no event_name) from the webapp. DataBlock.process_events
did event.pop("event_name") with no default, so this raised KeyError: 'event_name',
surfaced by the async worker as Error during processing: 'event_name' — unconditionally,
for every in-situ block use, regardless of the uploaded data.

Root cause chain

  1. webapp/src/components/datablocks/XRDInsituBlock.vue (onFolderSelected/onGranularitySubmit)
    calls updateBlockFromServer(..., { trigger_async: true }) when folder names are set.
    The NMR/UVVis in-situ blocks do the same.
  2. pydatalab/src/pydatalab/routes/v0_1/blocks.py schedules this as an async task and passes
    event_data straight through to the background worker.
  3. The worker calls block.process_events(event_data) since event_data is truthy.
  4. pydatalab/src/pydatalab/blocks/base.py's process_events does event.pop("event_name")
    with no default → KeyError: 'event_name', since the dict only has trigger_async.
  5. Caught by the async worker's outer handler and recorded as Error during processing: 'event_name'.

Fix

event.pop("event_name", None) — a control-only event is now treated as unregistered
and skipped rather than raising.

Test plan

  • Added test_process_events_ignores_events_without_event_name, covering the exact
    {"trigger_async": true} shape sent by the in-situ blocks.
  • Existing test_base_block still passes, confirming real events still dispatch correctly.
  • Verified end-to-end: uploading an in-situ XRD zip and setting folder names through the
    web UI no longer errors, and the block loads.

🤖 Generated with Claude Code

https://claude.ai/code/session_018B6NG9uZJ66A6yMxpvaw4t

…ly events

The XRD/NMR/UVVis in-situ blocks trigger their async processing step by
posting a bare {"trigger_async": true} event from the webapp
(XRDInsituBlock.vue onFolderSelected/onGranularitySubmit, and the
equivalent NMR/UVVis handlers). This event carries no event_name key.

blocks.py schedules this as an async task and hands event_data straight
to the background worker, which calls block.process_events(event_data)
since the dict is truthy. process_events did event.pop("event_name")
with no default, so any event without an event_name key raised
KeyError: 'event_name', caught by the worker's outer handler and
recorded as "Error during processing: 'event_name'".

This fired unconditionally for every in-situ block use through the web
UI, regardless of the uploaded data. Fix: pop with a None default so
events with no event_name are treated as unregistered (i.e. ignored)
rather than raising.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B6NG9uZJ66A6yMxpvaw4t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant