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 federation data is sent as an object rather than an array.
  • Tests

    • Added a test to verify that 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)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Suggested labels

enhancement, CI, maintenance

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 1bb9668 and 90240b3.

📒 Files selected for processing (1)
  • tests/Endpoints/MultiSearchTest.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Endpoints/MultiSearchTest.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: integration-tests (PHP 8.2)
  • GitHub Check: integration-tests (PHP 8.0)
  • GitHub Check: integration-tests (PHP 7.4)
  • GitHub Check: integration-tests (PHP 8.4)
  • GitHub Check: integration-tests (PHP 8.3)
  • GitHub Check: integration-tests (PHP 8.1)
✨ 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 😑

@adrenallen
Copy link

Bump! Would love to get this merged, if I can assist lmk!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

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

📒 Files selected for processing (2)
  • src/Endpoints/Delegates/HandlesMultiSearch.php (1 hunks)
  • tests/Endpoints/MultiSearchTest.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Endpoints/Delegates/HandlesMultiSearch.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/Endpoints/MultiSearchTest.php (4)
src/Client.php (1)
  • Client (32-68)
src/Endpoints/Delegates/HandlesMultiSearch.php (1)
  • multiSearch (18-32)
src/Contracts/SearchQuery.php (2)
  • SearchQuery (7-495)
  • setIndexUid (365-370)
src/Contracts/MultiSearchFederation.php (1)
  • MultiSearchFederation (7-94)
🪛 GitHub Check: phpstan-tests
tests/Endpoints/MultiSearchTest.php

[failure] 184-184:
Call to static method PHPUnit\Framework\Assert::assertCount() with 1 and array{} will always evaluate to false.


[failure] 176-176:
Parameter #3 $httpClient of class Meilisearch\Client constructor expects Psr\Http\Client\ClientInterface|null, GuzzleHttp\Client given.


[failure] 176-176:
Instantiated class GuzzleHttp\Client not found.


[failure] 174-174:
Call to static method history() on an unknown class GuzzleHttp\Middleware.


[failure] 171-171:
Instantiated class GuzzleHttp\Handler\MockHandler not found.


[failure] 171-171:
Call to static method create() on an unknown class GuzzleHttp\HandlerStack.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: integration-tests (PHP 8.3)
  • GitHub Check: integration-tests (PHP 8.4)
  • GitHub Check: integration-tests (PHP 8.0)
  • GitHub Check: integration-tests (PHP 8.1)
  • GitHub Check: integration-tests (PHP 8.2)
  • GitHub Check: integration-tests (PHP 7.4)
🔇 Additional comments (1)
tests/Endpoints/MultiSearchTest.php (1)

7-11: LGTM! Appropriate imports for HTTP mocking.

The imports are correctly added for setting up Guzzle HTTP client mocking to test the federation payload structure.

@norkunas
Copy link
Collaborator Author

If i'll have time later today then will complete,otherwise will fix after my holidays

Copy link

codecov bot commented Jul 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.78%. Comparing base (0078a8c) to head (90240b3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #757   +/-   ##
=======================================
  Coverage   89.78%   89.78%           
=======================================
  Files          59       59           
  Lines        1449     1449           
=======================================
  Hits         1301     1301           
  Misses        148      148           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@norkunas
Copy link
Collaborator Author

This is ready. @Strift @brunoocasali can you review

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
3 participants