HumanSignal / HumanSignal/label-studio-sdk

LS Client crash when passing `None` as the `api_key`

Open
#145 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
192
Forks
127
Avg merge
1d 18h
Merged PRs (30d)
1

Description

**Describe the bug**
If you pass `None` as your `api_key` and you don't have your `LABEL_STUDIO_API_KEY` env var set when creating a `label_studio_sdk.Client`, you'll get an `AttributeError` when trying to access `credentials.api_key`.

This happens because, the check for `api_key` being `None` and using `credentials` is wrong on client.py:
https://github.com/HumanSignal/label-studio-sdk/blob/415049a6834db4f8cff4dec3e72755c26f6a2c38/label_studio_sdk/client.py#L83-L92

**To Reproduce**
Run the following without setting your `LABEL_STUDIO_API_KEY` env var.
```python
>>> import label_studio_sdk
>>> label_studio_sdk.Client()
```
```
Traceback (most recent call last):
File "", line 1, in
File "/path/to/label_studio_sdk/client.py", line 90, in __init__
if credentials.api_key
AttributeError: 'NoneType' object has no attribute 'api_key'
```

**Expected behavior**
Since you can't really do anything at this point (no api_key and no credentials), the SDK should just raise an error with a better error message. It's a small change and I could probably make a PR for it when I have some time 😅, but just thought of creating the issue in case anyone is able to fix this first.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.