Skip to content

Commit 6888eff

Browse files
phernandezclaude
andauthored
fix: correct get_default_project() query to check for True instead of not NULL (#521)
Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 38616c3 commit 6888eff

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/basic_memory/repository/project_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def get_by_external_id(self, external_id: str) -> Optional[Project]:
8888

8989
async def get_default_project(self) -> Optional[Project]:
9090
"""Get the default project (the one marked as is_default=True)."""
91-
query = self.select().where(Project.is_default.is_not(None))
91+
query = self.select().where(Project.is_default.is_(True))
9292
return await self.find_one(query)
9393

9494
async def get_active_projects(self) -> Sequence[Project]:

tests/repository/test_project_repository.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,39 @@ async def test_get_default_project(project_repository: ProjectRepository, test_p
136136
assert default_project.is_default is True
137137

138138

139+
@pytest.mark.asyncio
140+
async def test_get_default_project_with_false_values(project_repository: ProjectRepository):
141+
"""Test that get_default_project ignores projects with is_default=False.
142+
143+
Regression test for bug where is_not(None) matched both True and False,
144+
causing MultipleResultsFound when multiple projects had different boolean values.
145+
"""
146+
# Create projects with explicit is_default values
147+
project_true = await project_repository.create({
148+
"name": "Default Project",
149+
"path": "/default/path",
150+
"is_default": True,
151+
})
152+
153+
await project_repository.create({
154+
"name": "Not Default Project",
155+
"path": "/not-default/path",
156+
"is_default": False,
157+
})
158+
159+
await project_repository.create({
160+
"name": "Null Default Project",
161+
"path": "/null/path",
162+
"is_default": None,
163+
})
164+
165+
# Should return only the project with is_default=True
166+
default = await project_repository.get_default_project()
167+
assert default is not None
168+
assert default.id == project_true.id
169+
assert default.name == "Default Project"
170+
171+
139172
@pytest.mark.asyncio
140173
async def test_get_active_projects(project_repository: ProjectRepository):
141174
"""Test getting all active projects."""

0 commit comments

Comments
 (0)