revert changes for delete_command
This commit is contained in:
parent
0a644999c5
commit
e4a2188820
1 changed files with 11 additions and 22 deletions
|
|
@ -1,14 +1,12 @@
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
from uuid import UUID
|
from typing import Optional
|
||||||
|
|
||||||
from cognee.cli.reference import SupportsCliCommand
|
from cognee.cli.reference import SupportsCliCommand
|
||||||
from cognee.cli import DEFAULT_DOCS_URL
|
from cognee.cli import DEFAULT_DOCS_URL
|
||||||
import cognee.cli.echo as fmt
|
import cognee.cli.echo as fmt
|
||||||
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
|
from cognee.cli.exceptions import CliCommandException, CliCommandInnerException
|
||||||
from cognee.modules.data.methods.get_deletion_counts import get_deletion_counts
|
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):
|
class DeleteCommand(SupportsCliCommand):
|
||||||
|
|
@ -95,27 +93,18 @@ Be careful with deletion operations as they are irreversible.
|
||||||
# Run the async delete function
|
# Run the async delete function
|
||||||
async def run_delete():
|
async def run_delete():
|
||||||
try:
|
try:
|
||||||
if args.dataset_name:
|
# NOTE: The underlying cognee.delete() function is currently not working as expected.
|
||||||
# Use delete_datasets_by_name for dataset deletion
|
# This is a separate bug that this preview feature helps to expose.
|
||||||
user = await get_default_user()
|
if args.all:
|
||||||
result = await delete_dataset_by_name(args.dataset_name, user.id)
|
await cognee.delete(dataset_name=None, user_id=args.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
|
|
||||||
else:
|
else:
|
||||||
# For user_id deletion, use the original cognee.delete
|
await cognee.delete(dataset_name=args.dataset_name, user_id=args.user_id)
|
||||||
result = await delete_data_by_user(UUID(args.user_id))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise CliCommandInnerException(f"Failed to delete: {str(e)}") from e
|
raise CliCommandInnerException(f"Failed to delete: {str(e)}") from e
|
||||||
return True
|
|
||||||
|
|
||||||
success = asyncio.run(run_delete())
|
asyncio.run(run_delete())
|
||||||
if success and not args.dataset_name:
|
# This success message may be inaccurate due to the underlying bug, but we leave it for now.
|
||||||
fmt.success(f"Successfully deleted {operation}")
|
fmt.success(f"Successfully deleted {operation}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, CliCommandInnerException):
|
if isinstance(e, CliCommandInnerException):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue