Skip to content

Conversation

@zigzagdev
Copy link
Contributor

Description

This pull request introduces a small but important fix to ensure response consistency across multiple calls to setResponse() within the Elastic\Elasticsearch\Response\Elasticsearch class.

Previously, when a new PSR-7 ResponseInterface was passed to setResponse(), any previously cached data in $asArray, $asObject, or $asString persisted. This could lead to incorrect data being returned if the same Elasticsearch instance was reused.

To resolve this, the following change has been applied:

unset($this->asArray, $this->asObject);
$this->asString = '';

These lines ensure that any previously serialised body representations are cleared whenever a new response is set.

Why

Without clearing the cached serialised data, the same Elasticsearch instance could return
stale results from a previous response. This becomes problematic when multiple responses
are handled in sequence — for example, in integration tests or long-running processes that
reuse the same client instance.

Resetting these cached properties ensures that the object always reflects the latest
response body, maintaining consistency and correctness without affecting public APIs.
This change is small, isolated, and backward compatible, yet it prevents subtle and
potentially confusing data inconsistencies.

Tests Results

スクリーンショット 2025-10-27 14 18 06

I hope this fix will help for !!! 🙌

@zigzagdev zigzagdev requested a review from a team as a code owner October 27, 2025 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant