From dce26e82768724835a4f1dfd5fee7f5d18cc5e37 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 27 Aug 2025 01:17:40 +0000 Subject: [PATCH] fix: Address CI failures - type annotations, lint, security MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix TypeAlias annotation in elasticsearch/types.py using TYPE_CHECKING - Add 'elasticsearch' to _MissingProvider Literal type in base.py - Remove unused variable in test_client.py - Add usedforsecurity=False to MD5 hash in config.py for security check Co-Authored-By: João --- src/crewai/rag/config/optional_imports/base.py | 2 +- src/crewai/rag/elasticsearch/config.py | 2 +- src/crewai/rag/elasticsearch/types.py | 15 ++++++++++----- tests/rag/elasticsearch/test_client.py | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/crewai/rag/config/optional_imports/base.py b/src/crewai/rag/config/optional_imports/base.py index ba6657ec4..e9a2f0050 100644 --- a/src/crewai/rag/config/optional_imports/base.py +++ b/src/crewai/rag/config/optional_imports/base.py @@ -14,7 +14,7 @@ class _MissingProvider: Raises RuntimeError when instantiated to indicate missing dependencies. """ - provider: Literal["chromadb", "qdrant", "__missing__"] = field( + provider: Literal["chromadb", "qdrant", "elasticsearch", "__missing__"] = field( default="__missing__" ) diff --git a/src/crewai/rag/elasticsearch/config.py b/src/crewai/rag/elasticsearch/config.py index 2a88cecfe..1fbbb22c3 100644 --- a/src/crewai/rag/elasticsearch/config.py +++ b/src/crewai/rag/elasticsearch/config.py @@ -61,7 +61,7 @@ def _default_embedding_function() -> ElasticsearchEmbeddingFunctionWrapper: import hashlib import struct - hash_obj = hashlib.md5(text.encode()) + hash_obj = hashlib.md5(text.encode(), usedforsecurity=False) hash_bytes = hash_obj.digest() vector = [] diff --git a/src/crewai/rag/elasticsearch/types.py b/src/crewai/rag/elasticsearch/types.py index 841c39f0f..c1f952b5a 100644 --- a/src/crewai/rag/elasticsearch/types.py +++ b/src/crewai/rag/elasticsearch/types.py @@ -1,15 +1,20 @@ """Type definitions for Elasticsearch RAG implementation.""" -from typing import Any, Protocol, TypedDict, Union +from typing import Any, Protocol, TypedDict, Union, TYPE_CHECKING from typing_extensions import NotRequired from pydantic import GetCoreSchemaHandler from pydantic_core import CoreSchema, core_schema -try: +if TYPE_CHECKING: + from typing import TypeAlias from elasticsearch import Elasticsearch, AsyncElasticsearch - ElasticsearchClientType = Union[Elasticsearch, AsyncElasticsearch] -except ImportError: - ElasticsearchClientType = Any + ElasticsearchClientType: TypeAlias = Union[Elasticsearch, AsyncElasticsearch] +else: + try: + from elasticsearch import Elasticsearch, AsyncElasticsearch + ElasticsearchClientType = Union[Elasticsearch, AsyncElasticsearch] + except ImportError: + ElasticsearchClientType = Any class ElasticsearchClientParams(TypedDict, total=False): diff --git a/tests/rag/elasticsearch/test_client.py b/tests/rag/elasticsearch/test_client.py index 7cb0e19d5..901c55864 100644 --- a/tests/rag/elasticsearch/test_client.py +++ b/tests/rag/elasticsearch/test_client.py @@ -179,7 +179,7 @@ class TestElasticsearchClient: """Test that get_or_create_collection creates new index if not exists.""" mock_elasticsearch_client.indices.exists.return_value = False - result = client.get_or_create_collection(collection_name="test_index") + client.get_or_create_collection(collection_name="test_index") mock_elasticsearch_client.indices.exists.assert_called_once_with(index="test_index") mock_elasticsearch_client.indices.create.assert_called_once()