Bug: Project lookup fails without permalink normalization in deps.py
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:
- Import
generate_permalinkfrombasic_memory.utils - Convert project name to permalink before lookup
- 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.
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_permalinkutility 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:
get_project_config()- Directly passedstr(project)toget_by_permalink()get_project_id()- Directly passedstr(project)toget_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:
- Added import:
from basic_memory.utils import generate_permalink - In
get_project_config(): Convert project name to permalink before lookup - In
get_project_id(): Convert project name to permalink before lookup
Changes:
src/basic_memory/deps.py:36- Added importsrc/basic_memory/deps.py:66-67- Normalize inget_project_config()src/basic_memory/deps.py:154-155- Normalize inget_project_id()
This matches the fix pattern from #345 and ensures consistent project resolution across the API.