Fix Taks.get_project_id() cannot find hidden projects

This commit is contained in:
allegroai 2023-01-24 13:16:10 +02:00
parent e0bea7f586
commit 00464a879b

View File

@ -2144,8 +2144,8 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
return ret_projects return ret_projects
@classmethod @classmethod
def get_project_id(cls, project_name): def get_project_id(cls, project_name, search_hidden=True):
# type: (str) -> Optional[str] # type: (str, bool) -> Optional[str]
""" """
Return a project's unique ID (str). Return a project's unique ID (str).
If more than one project matched the project_name, return the last updated project If more than one project matched the project_name, return the last updated project
@ -2155,9 +2155,14 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
""" """
assert project_name assert project_name
assert isinstance(project_name, str) assert isinstance(project_name, str)
extra = {"search_hidden": search_hidden} if Session.check_min_api_version("2.20") else {}
res = cls._send( res = cls._send(
cls._get_default_session(), cls._get_default_session(),
projects.GetAllRequest(order_by=['last_update'], name=exact_match_regex(project_name)), projects.GetAllRequest(
order_by=['last_update'],
name=exact_match_regex(project_name),
**extra
),
raise_on_errors=False) raise_on_errors=False)
if res and res.response and res.response.projects: if res and res.response and res.response.projects:
return [projects.Project(**p.to_dict()).id for p in res.response.projects][0] return [projects.Project(**p.to_dict()).id for p in res.response.projects][0]