basic-memory icon indicating copy to clipboard operation
basic-memory copied to clipboard

Bug: Project lookup fails without permalink normalization in deps.py

Open jope-bm opened this issue 1 year ago • 1 comments

Summary

Project lookups in the dependency injection functions get_project_config() and get_project_id() were failing when project names contained characters that needed permalink normalization (e.g., spaces, special characters).

Problem

The get_project_config() and get_project_id() functions in src/basic_memory/deps.py were directly passing project names to project_repository.get_by_permalink() without first converting them to permalinks using generate_permalink().

This caused lookups to fail for projects with names containing:

  • Spaces
  • Special characters
  • Capital letters that should be normalized

Root Cause

Location: src/basic_memory/deps.py:61-68 and src/basic_memory/deps.py:147-154

The code was doing:

project_obj = await project_repository.get_by_permalink(str(project))

Instead of:

project_permalink = generate_permalink(str(project))
project_obj = await project_repository.get_by_permalink(project_permalink)

Solution

Added permalink normalization before database lookups in both functions:

  1. Import generate_permalink from basic_memory.utils
  2. Convert project name to permalink before lookup
  3. Use normalized permalink for database query

Impact

This bug would have caused:

  • 404 errors when accessing projects via API with non-normalized names
  • Inconsistent behavior between different project name formats
  • Failed project resolution in dependency injection chain

Related

Similar to the fix in #345 for project deletion with permalink normalization.

jope-bm avatar Oct 10 '25 20:10 jope-bm

Claude finished @jope-bm's task —— View job • claude/issue-347-20251010-2056 • Create PR ➔


Issue Triage & Fix Complete ✓

Classification:

  • Type: Bug (code defect in dependency injection)
  • Priority: High (causes 404 errors for projects with normalized names)
  • Component: Database/API dependency injection
  • Complexity: Simple (straightforward fix with clear solution)

Todo List:

  • [x] Read and verify the bug in src/basic_memory/deps.py
  • [x] Check for generate_permalink utility function
  • [x] Implement the fix (add permalink normalization)
  • [x] Commit and push changes
  • [x] Provide PR creation link

Analysis

Confirmed Bug: In src/basic_memory/deps.py, two functions were missing permalink normalization:

  1. get_project_config() - Directly passed str(project) to get_by_permalink()
  2. get_project_id() - Directly passed str(project) to get_by_permalink()

Root Cause: Project names from URL paths need to be normalized to permalinks before database lookup. Projects with spaces, special characters, or capitals failed because the database stores normalized permalinks.

Fix Applied

Added permalink normalization in both functions:

  1. Added import: from basic_memory.utils import generate_permalink
  2. In get_project_config(): Convert project name to permalink before lookup
  3. In get_project_id(): Convert project name to permalink before lookup

Changes:

  • src/basic_memory/deps.py:36 - Added import
  • src/basic_memory/deps.py:66-67 - Normalize in get_project_config()
  • src/basic_memory/deps.py:154-155 - Normalize in get_project_id()

This matches the fix pattern from #345 and ensures consistent project resolution across the API.


claude[bot] avatar Oct 10 '25 20:10 claude[bot]