entity rename debugging

This commit is contained in:
phernandez
2024-12-11 21:24:41 -06:00
parent 747277a832
commit a3ad0fa545
2 changed files with 15 additions and 18 deletions
+4 -4
View File
@@ -19,7 +19,7 @@ class EntityNotFoundError(Exception):
pass
async def write_entity_file(entities_path: Path, entity: EntityIn) -> bool:
async def write_entity_file(entities_path: Path, entity_id: str, entity: EntityIn) -> bool:
"""
Write entity to filesystem in markdown format.
@@ -33,9 +33,9 @@ async def write_entity_file(entities_path: Path, entity: EntityIn) -> bool:
Raises:
FileOperationError: If file operations fail
"""
logger.debug(f"Writing entity file for {entity.file_path}")
logger.debug(f"Writing entity file for {entity_id}")
entity_path = entities_path / entity.file_path
entity_path = entities_path / entity_id
# Handle directory creation separately
try:
@@ -84,7 +84,7 @@ async def write_entity_file(entities_path: Path, entity: EntityIn) -> bool:
except Exception as e:
raise FileOperationError(f"Failed to finalize entity file: {str(e)}") from e
logger.debug(f"Wrote entity file: {entity.file_path}")
logger.debug(f"Wrote entity file: {entity_id}")
return True
+11 -14
View File
@@ -33,28 +33,25 @@ class MemoryService:
"""Create multiple entities with their observations."""
logger.debug(f"Creating {len(entities_in)} entities")
# First check if any entities already exist and generate IDs
for entity in entities_in:
# Generate ID upfront
entity.id = Entity.generate_id(entity.entity_type, entity.name)
logger.debug(f"Generated ID for entity: {entity.id}")
# Check if entity exists
# Write files in parallel (filesystem is source of truth)
async def write_file(entity: EntityIn):
try:
existing = await self.entity_service.get_by_type_and_name(
entity.entity_type,
entity.entity_type,
entity.name
)
if existing:
raise ValueError(
logger.error(
f"Entity already exists: {entity.entity_type}/{entity.name}"
)
except EntityNotFoundError:
# This is good - means entity doesn't exist
pass
# Write files in parallel (filesystem is source of truth)
async def write_file(entity: EntityIn):
except EntityNotFoundError:
# TODO replace with self.entity_service.exists(entity.entity_type, entity.name)
return
# Generate ID and data dict for this entity
entity_id = Entity.generate_id(entity.entity_type, entity.name)
await write_entity_file(self.entities_path, entity)
file_writes = [write_file(entity) for entity in entities_in]