fix: forward $args in Index::forcemerge to Elasticsearch#2301
Conversation
A malformed `array_merge(['index' => $name, $args])` call (single argument instead of two) caused user-supplied options like `max_num_segments` and `flush` to be silently appended at a numeric key inside the metadata array, never reaching Elasticsearch. Tighten the parameter type from untyped to `array` and merge the arguments correctly. Add a functional test that asserts the options surface in the last HTTP request's query string.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes a bug in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 5/8 reviews remaining, refill in 19 minutes and 1 second.Comment |
There was a problem hiding this comment.
Pull request overview
Fixes Elastica\Index::forcemerge() so caller-supplied options are actually forwarded to Elasticsearch (previously dropped due to a malformed array_merge()), and adds coverage + changelog note.
Changes:
- Correctly merges
['index' => $this->getName()]with$argswhen calling the Elasticsearch indices forcemerge API. - Adds a functional test asserting the provided options appear in the last HTTP request’s query string.
- Updates the changelog to document the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Index.php | Fixes request parameter assembly for Index::forcemerge() (and adds an array type-hint). |
| tests/IndexTest.php | Adds a functional regression test ensuring forcemerge() forwards query args. |
| CHANGELOG.md | Documents the fix in the Unreleased “Fixed” section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function forcemerge(array $args = []): Response | ||
| { |
There was a problem hiding this comment.
Index::forcemerge() is a public API; narrowing the parameter from untyped to array is a backward-incompatible signature change for any callers currently passing non-arrays (even if those values were previously ignored due to the bug). If BC is a concern for patch/minor releases, consider keeping the parameter untyped and validating/casting internally (or explicitly documenting this as a BC break).
| public function forcemerge(array $args = []): Response | |
| { | |
| public function forcemerge($args = []): Response | |
| { | |
| $args = \is_array($args) ? $args : []; |
| ### Deprecated | ||
| ### Removed | ||
| ### Fixed | ||
| * Fixed `Elastica\Index::forcemerge()` silently dropping the `$args` argument due to a malformed `array_merge()` call. Additional options such as `max_num_segments` and `flush` are now forwarded to Elasticsearch as documented. |
There was a problem hiding this comment.
This entry describes the forwarding fix, but the PR also changes Index::forcemerge()'s public method signature by adding an array type-hint. If you keep the type change, it should be called out under “Backward Compatibility Breaks” (or the type change should be reverted) so consumers aren’t surprised by a new TypeError.
Summary
Elastica\Index::forcemerge()had a malformedarray_merge()call:This is a single-argument
array_merge, so$argsended up as a numerickey inside the metadata array and was never sent to Elasticsearch. Options
like
max_num_segments,flush, oronly_expunge_deleteswere silentlyignored.
The fix:
array_merge(['index' => $name], $args).array(matches PHPDoc).request's query string.
Identified during a P0/P1 code-review pass.
Test plan
make docker-run-phpunit PHPUNIT_OPTIONS="--filter=testForcemerge"Summary by CodeRabbit
Release Notes