Skip to content

Cast federation payload explicilty to an object #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

norkunas
Copy link
Collaborator

@norkunas norkunas commented May 29, 2025

Pull Request

Related issue

Fixes #685
Replaces #686

What does this PR do?

  • It casts the federation payload explicitly to an object. This solves the error that appears when no MultiSearchFederation properties have been set.

First commit is cherry-picked to give @thijskuilman original credit

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted the multi-search request payload so that the federation data is sent as an object rather than an array.
  • Tests

    • Added a test to verify that the federation data in multi-search requests is correctly serialized as an object.

@norkunas norkunas requested a review from Strift May 29, 2025 08:57
@norkunas norkunas added the bug Something isn't working label May 29, 2025
Copy link

coderabbitai bot commented May 29, 2025

Walkthrough

The change updates the multiSearch method to cast the federation data to an object before including it in the payload. A new test is added to verify that the federation key is serialized as an object, ensuring correct request formation when an empty MultiSearchFederation is used.

Changes

File(s) Change Summary
src/Endpoints/Delegates/HandlesMultiSearch.php Casts the federation array to an object in the multiSearch payload.
tests/Endpoints/MultiSearchTest.php Adds a test verifying the federation key is serialized as an object in the multiSearch request.

Sequence Diagram(s)

sequenceDiagram
    participant Test as MultiSearchTest
    participant Client as Meilisearch Client
    participant Handles as HandlesMultiSearch
    participant HTTP as HTTP Server

    Test->>Client: Call multiSearch(queries, federation)
    Client->>Handles: multiSearch(queries, federation)
    Handles->>Handles: Prepare payload (federation cast to object)
    Handles->>HTTP: Send POST request with payload
    HTTP-->>Handles: Return response
    Handles-->>Client: Return response
    Client-->>Test: Return response
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure federated multi-search works with an empty MultiSearchFederation instance (#685)

Poem

In the warren of code, a bug did hop,
Empty federation made the search flop.
Now cast as an object, the payload is neat,
Multi-search works—oh, what a treat!
With tests to ensure all is right,
The rabbits rejoice, coding through the night. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a5bef7 and 6839aef.

📒 Files selected for processing (2)
  • src/Endpoints/Delegates/HandlesMultiSearch.php (1 hunks)
  • tests/Endpoints/MultiSearchTest.php (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Tests
tests/Endpoints/MultiSearchTest.php

[error] 171-171: PHPUnit test error: Class "GuzzleHttp\HandlerStack" not found in testMultiSearchFederationCastingToObject.

🔇 Additional comments (3)
src/Endpoints/Delegates/HandlesMultiSearch.php (1)

28-28: LGTM! Object casting correctly addresses empty federation serialization.

The explicit cast to (object) ensures that the federation payload is serialized as a JSON object {} rather than an array [] when empty. This addresses the issue where no properties of MultiSearchFederation have been set, ensuring consistent API payload structure.

tests/Endpoints/MultiSearchTest.php (2)

168-189: Well-designed test that correctly validates object casting behavior.

The test implementation effectively validates that the federation payload is serialized as a JSON object {} rather than an array []. The use of request history middleware to capture and inspect the actual HTTP request body is a solid testing approach.

The assertion on line 188 correctly verifies the expected JSON structure with an empty federation object.

🧰 Tools
🪛 GitHub Actions: Tests

[error] 171-171: PHPUnit test error: Class "GuzzleHttp\HandlerStack" not found in testMultiSearchFederationCastingToObject.


7-11:

❌ Incorrect review comment

Fix missing import causing pipeline failure.

The pipeline failure indicates that GuzzleHttp\HandlerStack cannot be found. This suggests either a missing import or incorrect namespace.

Please verify the correct import path for HandlerStack. If using Guzzle 7+, try:

-use GuzzleHttp\HandlerStack;
+use GuzzleHttp\HandlerStack;

Or check if HandlerStack needs to be imported from a different namespace in your Guzzle version:


🏁 Script executed:

#!/bin/bash
# Check if HandlerStack class exists and find its correct namespace
grep -r "class HandlerStack" vendor/guzzlehttp/ || echo "HandlerStack not found in vendor/guzzlehttp/"
composer show guzzlehttp/guzzle | grep -E "^versions"

Length of output: 189


No import issue with HandlerStack

Grep confirms that HandlerStack is defined in vendor/guzzlehttp/guzzle/src/HandlerStack.php under namespace GuzzleHttp, so the line

use GuzzleHttp\HandlerStack;

is correct. The test logic itself is solid and should remain approved. The pipeline failure likely stems from how dependencies are installed or autoloaded in the CI environment rather than an incorrect namespace.

• Verify that guzzlehttp/guzzle (v7.9.3) is included in your Composer dependencies
• Ensure composer install (or composer dump-autoload) is run before executing tests

Likely an incorrect or invalid review comment.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@norkunas
Copy link
Collaborator Author

Ah shit, tests won't work in all CI jobs, because there is always different http client 😑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Federated multi-search example does not work
2 participants