Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: agent deletion bug from source cascade (#1101)
cthomas1bfa8acfe169
diff --git a/letta/orm/source.py b/letta/orm/source.pyindex 055f140e2..b71e3989e 100644--- a/letta/orm/source.py+++ b/letta/orm/source.py@@ -42,6 +42,6 @@ class Source(SqlalchemyBase, OrganizationMixin):secondary="sources_agents",back_populates="sources",lazy="selectin",- cascade="all, delete", # Ensures rows in sources_agents are deleted when the source is deleted- passive_deletes=True, # Allows the database to handle deletion of orphaned rows+ cascade="save-update", # Only propagate save and update operations+ passive_deletes=True, # Let the database handle deletions)diff --git a/tests/test_managers.py b/tests/test_managers.pyindex 8d078acfd..4d207d8a3 100644--- a/tests/test_managers.py+++ b/tests/test_managers.py@@ -2150,6 +2150,30 @@ def test_delete_source(server: SyncServer, default_user):assert len(sources) == 0+def test_delete_attached_source(server: SyncServer, sarah_agent, default_user):+ """Test deleting a source."""+ source_pydantic = PydanticSource(+ name="To Delete", description="This source will be deleted.", embedding_config=DEFAULT_EMBEDDING_CONFIG+ )+ source = server.source_manager.create_source(source=source_pydantic, actor=default_user)++ server.agent_manager.attach_source(agent_id=sarah_agent.id, source_id=source.id, actor=default_user)++ # Delete the source+ deleted_source = server.source_manager.delete_source(source_id=source.id, actor=default_user)++ # Assertions to verify deletion+ assert deleted_source.id == source.id++ # Verify that the source no longer appears in list_sources+ sources = server.source_manager.list_sources(actor=default_user)+ assert len(sources) == 0++ # Verify that agent is not deleted+ agent = server.agent_manager.get_agent_by_id(sarah_agent.id, actor=default_user)+ assert agent is not None++def test_list_sources(server: SyncServer, default_user):"""Test listing sources with pagination."""# Create multiple sources