Error in log when project.tasks_ids
tonal opened this issue · 3 comments
tonal commented
ls = Client(url=label_studio_url, api_key=api_key)
ls.get_project(PROJECT_ID)
tasks_ids = pr.tasks_ids
in log:
Request URL: http://example-label-studio.test:9200/api/tasks?project=1&page=2&page_size=100&query=%7B%22filters%22%3A+null%2C+%22ordering%22%3A+%5B%5D%2C+%22selectedItems%22%3A+%7B%22all%22%3A+true%2C+%22excluded%22%3A+%5B%5D%7D%7D&fields=all&resolve_uri=True&include=id
Response status code: 404
Response content:
{
"id": "5864cb16-36bb-4ce6-af9b-0b5c16992a88",
"status_code": 404,
"version": "1.8.0",
"detail": "Invalid page.",
"exc_info": null
}
SDK error traceback:
ClaytonSmith commented
I'm hitting this too. The pagination is broken, hitting the last page always results in an error. It can be ignored but its annoying bc the error text is not catchable.
ClaytonSmith commented
ok, its kinda shitty but here's a work around if you absolutely don't want fake error messages in your logs:
Warning: This will hide ALL error messages
from label_studio_sdk import Client
from label_studio_sdk.data_manager import Filters, Column, Type, Operator
# I have UUIDs for all my data, I need to get task_id given a UUID
def get_tasks_from_guid(project, guids):
# Create a filter that filters for the tasks that have the guids
filter = Filters.create(Filters.OR, [
Filters.item(
Column.data('guid'),
Operator.EQUAL,
Type.String,
guid )
for guid in guids]
)
params = dict(
filters=filter,
page=1,
page_size=250,
)
res = []
try:
while True:
res += project.get_paginated_tasks(
**params
)['tasks']
params['page'] += 1
except Exception as e:
pass
return res
LABEL_STUDIO_URL='<URL>'
API_KEY='<SECRETS>'
project_id = 0 # Enter your project id
guids = [ ... ]
# Note the make_request_raise kwarg
ls = Client(url=LABEL_STUDIO_URL, api_key=API_KEY, make_request_raise=False)
# Get the project
project = ls.get_project(project_id )
# Query for tasks
res = get_tasks_from_guid(project, guids)
If you don't care to filter, you can remove all the filter logic and related args.
jombooth commented
This was fixed in 0.0.32, see #149 (comment)