Skip to content

SCIM User helper crashes with UnboundLocalError instead of returning an error #666

Open

Description

@RaphaelFakhri

Every method in wandb-scim/users.py handles HTTP errors like this:

try:
    response = requests.get(url, **self.request_kwargs)
except requests.HTTPError:
    return {"error": f"Get user failed. Status code: {response.status_code}", ...}

request_kwargs installs a response hook that calls raise_for_status(). The hook raises inside requests.get(), before the assignment to response completes. The except branch then reads an unbound local and raises UnboundLocalError, so the documented error return values ("User not found", {"error": ...}) are never reached.

This affects all 10 methods: create, get, get_all, activate, deactivate, delete, assign_org_role, assign_team_role, assign_registry_role, remove_registry_role. The pattern appeared in #613.

Steps to reproduce

from users import User

User("https://api.wandb.ai", "", "<api-key>").get("does-not-exist")

Actual result

UnboundLocalError: local variable 'response' referenced before assignment

Expected result

{"error": "Get user failed. Status code: 404", "details": "..."}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions