label-studio-sdk icon indicating copy to clipboard operation
label-studio-sdk copied to clipboard

Retrieving tasks with comments cause parsing error in SDK

Open jzeimen opened this issue 1 year ago • 2 comments

The SDK cannot list tasks if there are comments currently.

Repro steps: Make a comment inside of a tab on a project. Use this project ID in the code below:

pip install label-studio-sdk==1.0.7

ls = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=API_KEY)
ls.tasks.list(project=115411)

Results in error

ValidationError                           Traceback (most recent call last)
Cell In[294], line 9
      1 from label_studio_sdk.data_manager import Filters, Column, Operator, Type
      2 filt = Filters.create(Filters.OR, [
      3     Filters.item(
      4         Column.data('clinic'),
   (...)
      7         Filters.value("youtube")
      8     )])
----> 9 ls.tasks.list(project=115411,  query='{"filters": ' + str(filt).replace("'",'"')+ '}')

File ~/miniconda3/envs/workspace/lib/python3.11/site-packages/label_studio_sdk/tasks/client_ext.py:10, in TasksClientExt.list(self, **kwargs)
      7 def list(self, **kwargs) -> SyncPagerExt[T]:
      8     # use `fields: all` by default and return the full data
      9     kwargs['fields'] = kwargs.get('fields', 'all')
---> 10     return SyncPagerExt.from_sync_pager(super().list(**kwargs))

File ~/miniconda3/envs/workspace/lib/python3.11/site-packages/label_studio_sdk/tasks/client.py:215, in TasksClient.list(self, page, page_size, view, project, resolve_uri, fields, review, include, query, request_options)
    213 try:
    214     if 200 <= _response.status_code < 300:
--> 215         _parsed_response = pydantic_v1.parse_obj_as(TasksListResponse, _response.json())  # type: ignore
    216         _has_next = True
    217         _get_next = lambda: self.list(
    218             page=page + 1,
    219             page_size=page_size,
   (...)
    227             request_options=request_options,
    228         )

File ~/miniconda3/envs/workspace/lib/python3.11/site-packages/pydantic/v1/tools.py:38, in parse_obj_as(type_, obj, type_name)
     36 def parse_obj_as(type_: Type[T], obj: Any, *, type_name: Optional[NameFactory] = None) -> T:
     37     model_type = _get_parsing_type(type_, type_name=type_name)  # type: ignore[arg-type]
---> 38     return model_type(__root__=obj).__root__

File ~/miniconda3/envs/workspace/lib/python3.11/site-packages/pydantic/v1/main.py:341, in BaseModel.__init__(__pydantic_self__, **data)
    339 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    340 if validation_error:
--> 341     raise validation_error
    342 try:
    343     object_setattr(__pydantic_self__, '__dict__', values)

ValidationError: 1 validation error for ParsingModel[TasksListResponse]
__root__ -> tasks -> 0 -> comment_authors -> 0
  value is not a valid integer (type=type_error.integer)

jzeimen avatar Nov 21 '24 21:11 jzeimen

Hi @jzeimen this is currently a known bug. However, you can try the following workaround for now:

Adjust the fields Parameter: As a workaround, you can specify the fields you need when listing tasks to avoid the comment_authors field that's causing the issue: tasks = ls.tasks.list(project=115411, fields=['id', 'data', 'annotations'])

pennymares avatar Nov 27 '24 00:11 pennymares

Ticket 1128 has been created and addressed to our engineering team.

makseq avatar Dec 31 '24 01:12 makseq