Skip to content

Commit bc37ecf

Browse files
phernandezclaude
andcommitted
fix: handle project removal for cloud-only projects
**Problem:** Cloud projects that exist only in the database (not in config.json) couldn't be removed. The error "Project 'name' not found" occurred because config validation failed before database deletion. **Root cause:** - In cloud mode, projects can exist in database without config entries - ProjectService.remove_project() called config_manager.remove_project() first, which raised ValueError if project wasn't in config - This prevented removal of cloud-only projects **Solution:** 1. Check database first for project existence (source of truth) 2. Validate default project status from both database and config 3. Try to remove from config, but catch ValueError if not found 4. Always remove from database if project exists there **Additional fix:** - Project list Default column now shows in local mode (always) and in cloud mode only if default_project_mode is enabled - This fixes integration tests that expect to see default marker Fixes cloud-only project deletion bug. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent b049c5c commit bc37ecf

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/basic_memory/cli/commands/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ async def _list_projects():
8989
if config.cloud_mode_enabled:
9090
table.add_column("Local Path", style="yellow", no_wrap=True, overflow="fold")
9191

92-
# Only show Default column if default_project_mode is enabled
93-
if config.default_project_mode:
92+
# Show Default column in local mode or if default_project_mode is enabled in cloud mode
93+
show_default_column = not config.cloud_mode_enabled or config.default_project_mode
94+
if show_default_column:
9495
table.add_column("Default", style="magenta")
9596

9697
for project in result.projects:
@@ -108,8 +109,8 @@ async def _list_projects():
108109
local_path = format_path(local_path)
109110
row.append(local_path)
110111

111-
# Add default indicator if default_project_mode is enabled
112-
if config.default_project_mode:
112+
# Add default indicator if showing default column
113+
if show_default_column:
113114
row.append(is_default)
114115

115116
table.add_row(*row)

src/basic_memory/services/project_service.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,26 @@ async def remove_project(self, name: str, delete_notes: bool = False) -> None:
234234
if not self.repository: # pragma: no cover
235235
raise ValueError("Repository is required for remove_project")
236236

237-
# Get project path before removing from config
237+
# Get project from database first
238238
project = await self.get_project(name)
239-
project_path = project.path if project else None
239+
if not project:
240+
raise ValueError(f"Project '{name}' not found")
240241

241-
# First remove from config (this will validate the project exists and is not default)
242-
self.config_manager.remove_project(name)
242+
project_path = project.path
243243

244-
# Then remove from database using robust lookup
245-
if project:
246-
await self.repository.delete(project.id)
244+
# Check if project is default (in cloud mode, check database; in local mode, check config)
245+
if project.is_default or name == self.config_manager.config.default_project:
246+
raise ValueError(f"Cannot remove the default project '{name}'")
247+
248+
# Remove from config if it exists there (may not exist in cloud mode)
249+
try:
250+
self.config_manager.remove_project(name)
251+
except ValueError:
252+
# Project not in config - that's OK in cloud mode, continue with database deletion
253+
logger.debug(f"Project '{name}' not found in config, removing from database only")
254+
255+
# Remove from database
256+
await self.repository.delete(project.id)
247257

248258
logger.info(f"Project '{name}' removed from configuration and database")
249259

0 commit comments

Comments
 (0)