revert changes for delete_command

This commit is contained in:
rajeevrajeshuni 2025-11-30 14:08:30 +05:30
parent 0a644999c5
commit e4a2188820

View file

@ -1,14 +1,12 @@
import argparse
import asyncio
from uuid import UUID
from typing import Optional
from cognee.cli.reference import SupportsCliCommand
from cognee.cli import DEFAULT_DOCS_URL
import cognee.cli.echo as fmt
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
from cognee.modules.data.methods.get_deletion_counts import get_deletion_counts
from cognee.modules.data.methods.delete_dataset_by_name import delete_dataset_by_name
from cognee.modules.data.methods.delete_data_by_user import delete_data_by_user
from cognee.modules.users.methods import get_default_user
class DeleteCommand(SupportsCliCommand):
@ -95,29 +93,20 @@ Be careful with deletion operations as they are irreversible.
# Run the async delete function
async def run_delete():
try:
if args.dataset_name:
# Use delete_datasets_by_name for dataset deletion
user = await get_default_user()
result = await delete_dataset_by_name(args.dataset_name, user.id)
if result["not_found"]:
fmt.warning(f"Dataset '{args.dataset_name}' not found")
return False
fmt.success(f"Successfully deleted {result['deleted_count']} dataset(s)")
return True
# NOTE: The underlying cognee.delete() function is currently not working as expected.
# This is a separate bug that this preview feature helps to expose.
if args.all:
await cognee.delete(dataset_name=None, user_id=args.user_id)
else:
# For user_id deletion, use the original cognee.delete
result = await delete_data_by_user(UUID(args.user_id))
await cognee.delete(dataset_name=args.dataset_name, user_id=args.user_id)
except Exception as e:
raise CliCommandInnerException(f"Failed to delete: {str(e)}") from e
return True
success = asyncio.run(run_delete())
if success and not args.dataset_name:
fmt.success(f"Successfully deleted {operation}")
asyncio.run(run_delete())
# This success message may be inaccurate due to the underlying bug, but we leave it for now.
fmt.success(f"Successfully deleted {operation}")
except Exception as e:
if isinstance(e, CliCommandInnerException):
raise CliCommandException(str(e), error_code=1) from e
raise CliCommandException(f"Error deleting data: {str(e)}", error_code=1) from e
raise CliCommandException(f"Error deleting data: {str(e)}", error_code=1) from e