Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LS Client crash when passing None as the api_key #145

Open
GuilhermeFreire opened this issue Aug 10, 2023 · 0 comments
Open

LS Client crash when passing None as the api_key #145

GuilhermeFreire opened this issue Aug 10, 2023 · 0 comments

Comments

@GuilhermeFreire
Copy link
Contributor

GuilhermeFreire commented Aug 10, 2023

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:

if api_key is None and credentials is None:
api_key = os.getenv('LABEL_STUDIO_API_KEY')
if api_key is not None:
credentials = ClientCredentials(api_key=api_key)
self.api_key = (
credentials.api_key
if credentials.api_key
else self.get_api_key(credentials)
)

To Reproduce
Run the following without setting your LABEL_STUDIO_API_KEY env var.

>>> import label_studio_sdk
>>> label_studio_sdk.Client()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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.

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

No branches or pull requests

1 participant