-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SQLite log handling issue causing ValueError: Logs cannot be None…
… in tests (#1899) * Fix SQLite log handling issue causing ValueError: Logs cannot be None in tests - Add proper error handling in SQLite storage operations - Set up isolated test environment with temporary storage directory - Ensure consistent error messages across all database operations Co-Authored-By: Joe Moura <[email protected]> * fix: Sort imports in conftest.py Co-Authored-By: Joe Moura <[email protected]> * fix: Convert TokenProcess counters to instance variables to fix callback tracking Co-Authored-By: Joe Moura <[email protected]> * refactor: Replace print statements with logging and improve error handling - Add proper logging setup in kickoff_task_outputs_storage.py - Replace self._printer.print() with logger calls - Use appropriate log levels (error/warning) - Add directory validation in test environment setup - Maintain consistent error messages with DatabaseError format Co-Authored-By: Joe Moura <[email protected]> * fix: Comprehensive improvements to database and token handling - Fix SQLite database path handling in storage classes - Add proper directory creation and error handling - Improve token tracking with robust type checking - Convert TokenProcess counters to instance variables - Add standardized database error handling - Set up isolated test environment with temporary storage Resolves test failures in PR #1899 Co-Authored-By: Joe Moura <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Joe Moura <[email protected]> Co-authored-by: João Moura <[email protected]>
- Loading branch information
1 parent
294f2cc
commit 42311d9
Showing
7 changed files
with
193 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Error message definitions for CrewAI database operations.""" | ||
from typing import Optional | ||
|
||
|
||
class DatabaseOperationError(Exception): | ||
"""Base exception class for database operation errors.""" | ||
|
||
def __init__(self, message: str, original_error: Optional[Exception] = None): | ||
"""Initialize the database operation error. | ||
Args: | ||
message: The error message to display | ||
original_error: The original exception that caused this error, if any | ||
""" | ||
super().__init__(message) | ||
self.original_error = original_error | ||
|
||
|
||
class DatabaseError: | ||
"""Standardized error message templates for database operations.""" | ||
|
||
INIT_ERROR: str = "Database initialization error: {}" | ||
SAVE_ERROR: str = "Error saving task outputs: {}" | ||
UPDATE_ERROR: str = "Error updating task outputs: {}" | ||
LOAD_ERROR: str = "Error loading task outputs: {}" | ||
DELETE_ERROR: str = "Error deleting task outputs: {}" | ||
|
||
@classmethod | ||
def format_error(cls, template: str, error: Exception) -> str: | ||
"""Format an error message with the given template and error. | ||
Args: | ||
template: The error message template to use | ||
error: The exception to format into the template | ||
Returns: | ||
The formatted error message | ||
""" | ||
return template.format(str(error)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
# conftest.py | ||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
from dotenv import load_dotenv | ||
|
||
load_result = load_dotenv(override=True) | ||
|
||
@pytest.fixture(autouse=True) | ||
def setup_test_environment(): | ||
"""Set up test environment with a temporary directory for SQLite storage.""" | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
# Create the directory with proper permissions | ||
storage_dir = Path(temp_dir) / "crewai_test_storage" | ||
storage_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Validate that the directory was created successfully | ||
if not storage_dir.exists() or not storage_dir.is_dir(): | ||
raise RuntimeError(f"Failed to create test storage directory: {storage_dir}") | ||
|
||
# Verify directory permissions | ||
try: | ||
# Try to create a test file to verify write permissions | ||
test_file = storage_dir / ".permissions_test" | ||
test_file.touch() | ||
test_file.unlink() | ||
except (OSError, IOError) as e: | ||
raise RuntimeError(f"Test storage directory {storage_dir} is not writable: {e}") | ||
|
||
# Set environment variable to point to the test storage directory | ||
os.environ["CREWAI_STORAGE_DIR"] = str(storage_dir) | ||
|
||
yield | ||
|
||
# Cleanup is handled automatically when tempfile context exits |