Skip to content

Fix UnboundLocalError in SCIM User error handling - #667

Open
RaphaelFakhri wants to merge 1 commit into
wandb:mainfrom
RaphaelFakhri:fix/scim-users-http-error
Open

RaphaelFakhri wants to merge 1 commit into
wandb:mainfrom
RaphaelFakhri:fix/scim-users-http-error

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Description

wandb-scim/users.py installs a response hook that calls raise_for_status(). The hook raises HTTPError inside the requests call, so response is never assigned. Each except requests.HTTPError branch then reads response.status_code and fails with UnboundLocalError instead of returning the documented error value.

This change reads the response from the exception (e.response) in all 10 handlers. Successful requests are unchanged.

Fixes #666

Testing

A local HTTP server returns 404 (and 409 for POST) for every request, and the test calls each User method against it:

  • Before: 10 tests, 10 errors (UnboundLocalError).
  • After: 10 tests, all pass. Checked with requests==2.34.2 (the version pinned in wandb-scim/examples/requirements.txt) and 2.31.0.

The response hook raises HTTPError inside the requests call, so the
local response variable is never assigned and every except branch in
users.py failed with UnboundLocalError. Read the response from the
exception instead.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

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.

SCIM User helper crashes with UnboundLocalError instead of returning an error

2 participants