From 3c340f0b62f44196686b341da2fbecd9949c7c81 Mon Sep 17 00:00:00 2001 From: Igor Davidyuk Date: Tue, 16 Jul 2024 15:35:28 +0300 Subject: [PATCH] fix delete_project method (#466) Signed-off-by: Igor Davidyuk --- .../project_client/project_client.py | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/geti_sdk/rest_clients/project_client/project_client.py b/geti_sdk/rest_clients/project_client/project_client.py index 96bc8177..1a1f1fdd 100644 --- a/geti_sdk/rest_clients/project_client/project_client.py +++ b/geti_sdk/rest_clients/project_client/project_client.py @@ -512,16 +512,30 @@ def delete_project( raise TypeError(f"{type(project)} is not a valid project type.") if requires_confirmation: - media_response = self.session.get_rest_response( - url=f"{self.base_url}projects/{project.id}/datasets/" - f"{project.datasets[0].id}/media", - method="GET", - ) + # Update project details + project = self._get_project_detail(project) + if project.datasets is None: + project.datasets = [] + image_count = 0 + video_count = 0 + for dataset in project.datasets: + dataset_statistics = self.session.get_rest_response( + url=f"{self.base_url}projects/{project.id}/datasets/" + f"{dataset.id}/statistics", + method="GET", + ) + if dataset_statistics is dict: + dataset_statistics["overview"].get("image_count", 0) + image_count += dataset_statistics.get("images", 0) + video_count += dataset_statistics.get("videos", 0) + else: + logging.warning( + f"Unable to retrieve statistics for dataset {dataset.name}." + ) - media_count = media_response.get("media_count", {"images": 0, "videos": 0}) user_confirmation = input( f"CAUTION: You are about to delete project '{project.name}', " - f"containing {media_count['images']} images and {media_count['videos']}" + f"containing {image_count} images and {video_count}" f" videos, from the platform. Are you sure you want to continue? Type " f"Y or YES to continue, any other key to cancel." )