Fixes #21371: Fix Webhook Event Rules for Job lifecycle events missing username #342

Closed
opened 2026-04-05 16:26:42 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 2/16/2026

Fixes: #21371

This PR fixes webhook event rule processing for job lifecycle events (e.g. scripts) when the event context does not include the legacy username attribute. In these cases, webhook enqueueing raised a KeyError and incorrectly caused the job to be marked as errored, preventing the webhook from being sent.

Changes included:

  • Derive username from the associated user object when event["username"] is not present (maintaining backward compatibility for request-based events).
  • Add a regression test covering JOB_COMPLETED for extras.script to ensure a webhook is enqueued successfully when no request/legacy attributes are available.

Thanks for the review!

*Originally created by @pheus on 2/16/2026* ### Fixes: #21371 This PR fixes webhook event rule processing for **job lifecycle events** (e.g. scripts) when the event context does not include the legacy `username` attribute. In these cases, webhook enqueueing raised a `KeyError` and incorrectly caused the job to be marked as errored, preventing the webhook from being sent. **Changes included:** - Derive `username` from the associated `user` object when `event["username"]` is not present (maintaining backward compatibility for request-based events). - Add a regression test covering `JOB_COMPLETED` for `extras.script` to ensure a webhook is enqueued successfully when no request/legacy attributes are available. Thanks for the review!
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#342