Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions integrations/opensearch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [integrations/opensearch-v7.2.1] - 2026-04-10

### 🐛 Bug Fixes

- *(opensearch)* Pass positional args to `transport.perform_request` in `_query_sql` and `_query_sql_async` to fix compatibility with `ddtrace` Elasticsearch instrumentation (#PIP-226)

Comment thread
ArzelaAscoIi marked this conversation as resolved.
Outdated
## [integrations/opensearch-v7.2.0] - 2026-04-10

### 🚀 Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,8 @@ def _query_sql(self, query: str, fetch_size: int | None = None) -> dict[str, Any
body["fetch_size"] = fetch_size

response_data = self._client.transport.perform_request(
method="POST",
url="/_plugins/_sql",
"POST",
"/_plugins/_sql",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment explaining why we use positional args here, so we don't forget in the future

body=body,
)

Expand Down Expand Up @@ -2194,8 +2194,8 @@ async def _query_sql_async(self, query: str, fetch_size: int | None = None) -> d
body["fetch_size"] = fetch_size

response_data = await self._async_client.transport.perform_request(
method="POST",
url="/_plugins/_sql",
"POST",
"/_plugins/_sql",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a comment explaining why we use positional args here, so we don't forget in the future

body=body,
)

Expand Down
46 changes: 45 additions & 1 deletion integrations/opensearch/tests/test_sql_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

from unittest.mock import Mock, patch
from unittest.mock import AsyncMock, MagicMock, Mock, patch

import pytest
from haystack.dataclasses import Document
Expand Down Expand Up @@ -50,6 +50,50 @@ def test_from_dict(_mock_opensearch_client):
assert retriever_from_dict._raise_on_failure is True


@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
def test_query_sql_uses_positional_args(_mock_opensearch_class):
"""Verify perform_request is called with positional method/url args (ddtrace compatibility)."""
mock_transport = MagicMock()
mock_transport.perform_request.return_value = {"schema": [], "datarows": []}
mock_client = MagicMock()
mock_client.transport = mock_transport
_mock_opensearch_class.return_value = mock_client

document_store = OpenSearchDocumentStore(hosts="some fake host")
document_store._client = mock_client

document_store._query_sql(query="SELECT 1", fetch_size=10)

mock_transport.perform_request.assert_called_once()
call_args, call_kwargs = mock_transport.perform_request.call_args
assert call_args[0] == "POST"
assert call_args[1] == "/_plugins/_sql"
assert call_kwargs.get("body") == {"query": "SELECT 1", "fetch_size": 10}


@patch("haystack_integrations.document_stores.opensearch.document_store.AsyncOpenSearch")
@patch("haystack_integrations.document_stores.opensearch.document_store.OpenSearch")
@pytest.mark.asyncio
async def test_query_sql_async_uses_positional_args(_mock_opensearch_class, _mock_async_opensearch_class):
"""Verify async perform_request is called with positional method/url args (ddtrace compatibility)."""
mock_transport = MagicMock()
mock_transport.perform_request = AsyncMock(return_value={"schema": [], "datarows": []})
mock_async_client = MagicMock()
mock_async_client.transport = mock_transport
_mock_async_opensearch_class.return_value = mock_async_client

document_store = OpenSearchDocumentStore(hosts="some fake host")
document_store._async_client = mock_async_client

await document_store._query_sql_async(query="SELECT 1", fetch_size=10)

mock_transport.perform_request.assert_called_once()
call_args, call_kwargs = mock_transport.perform_request.call_args
assert call_args[0] == "POST"
assert call_args[1] == "/_plugins/_sql"
assert call_kwargs.get("body") == {"query": "SELECT 1", "fetch_size": 10}


@pytest.mark.integration
def test_sql_retriever_basic_query_hits_format(document_store: OpenSearchDocumentStore):
"""Test regular SELECT query - verifies raw response"""
Expand Down
Loading