mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
fix: Address CI failures - type annotations, lint, security
- 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 <joao@crewai.com>
This commit is contained in:
@@ -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__"
|
||||
)
|
||||
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user