-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Type Difference between Label Studio SDK and Label Studio
The field basic_auth_pass_is_set in the MlBackend model is currently typed as string in the OpenAPI spec used to generate the Label Studio SDK:
basic_auth_pass_is_set:
title: Basic auth pass is set
type: string
readOnly: trueHowever, the Label Studio backend returns a boolean:
def get_basic_auth_pass_is_set(self, obj):
return bool(obj.basic_auth_pass)Mismatch Triggers Errors
Here's example code that fails due to the type mismatch.
from label_studio_sdk import LabelStudio
ls = LabelStudio(
base_url="https://your.labelstudio.instance",
api_key="your-api-key",
)
ls.ml.list(project=your-project-id) # <- triggers error because backend includes `basic_auth_pass_is_set` as a booleanError Traceback
pydantic_core._pydantic_core.ValidationError: 2 validation errors for list[MlBackend]
0.basic_auth_pass_is_set
Input should be a valid string [type=string_type, input_value=False, input_type=bool]
For further information visit https://errors.pydantic.dev/2.11/v/string_type
0.extra_params
Input should be a valid dictionary [type=dict_type, input_value='', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/dict_type
Where the Related Code Appears in the SDK Code
1. SDK definition (generated):
| basic_auth_pass_is_set: typing.Optional[str] = None |
basic_auth_pass_is_set: typing.Optional[str] = None2. Runtime error in SDK occurs during this type check as the MlCreateResponse includes the expectation that the basic_auth_pass_is_set is as string. The Label Studio Server response has basic_auth_pass_is_set as as boolean, not as string:
| try: |
if 200 <= _response.status_code < 300:
return typing.cast(
MlCreateResponse,
parse_obj_as(
type_=MlCreateResponse, # type: ignore
object_=_response.json(),
),
)Proposed Fix
Update the OpenAPI spec field to:
basic_auth_pass_is_set:
title: Basic auth pass is set
type: boolean
readOnly: trueThis should regenerate the SDK with the correct type based on what I've read:
basic_auth_pass_is_set: typing.Optional[bool] = NoneAdditional Note
I'm not 100% sure whether the original intent was for this to be a string or a boolean, but based on the actual behavior of the backend, boolean seems to be the correct intended type.