Skip to content

Make some fields in *Stats structs optional to support older servers #690

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

Conversation

LukasKalbertodt
Copy link
Contributor

@LukasKalbertodt LukasKalbertodt commented Jul 28, 2025

These three fields were added in 1.13. If you want to support older servers, these fields need to be optional.

https://github.com/meilisearch/meilisearch/releases/tag/v1.13.0

Unfortunately, this is a breaking change for this library, which is unfortunate, as v0.29 not supporting older servers seems like a mistake to me. Should we solve this differently so that this can be released as a patch release? Or is it fine to just immediately release v0.30?

Summary by CodeRabbit

  • Documentation

    • Updated field descriptions to clarify that certain statistics may be unavailable when connecting to older Meilisearch servers.
  • New Features

    • Improved compatibility with older Meilisearch versions by allowing some statistics fields to be absent.

Copy link
Contributor

coderabbitai bot commented Jul 28, 2025

Walkthrough

Field types in the ClientStats and IndexStats structs were updated from non-optional (usize) to optional (Option<usize>) to reflect that these values may be absent for Meilisearch servers older than version 1.13. Documentation comments were updated accordingly. No logic or control flow changes were introduced.

Changes

Cohort / File(s) Change Summary
ClientStats Optional Field
src/client.rs
Changed used_database_size in ClientStats from usize to Option<usize>; updated docs and added #[serde(default)].
IndexStats Optional Fields
src/indexes.rs
Changed number_of_embedded_documents and number_of_embeddings in IndexStats from usize to Option<usize>; updated docs and added #[serde(default)].

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

In fields where options now may grow,
Some numbers might be missing, you know!
For older servers, don’t despair—
None means simply, “wasn’t there.”
Rusty bunnies hop with glee,
Optional stats for harmony! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 1ae5cc2 and 6ba586e.

📒 Files selected for processing (2)
  • src/client.rs (1 hunks)
  • src/indexes.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/indexes.rs
  • src/client.rs
⏰ 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). (1)
  • GitHub Check: integration-tests
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
src/indexes.rs (1)

1903-1908: Add #[serde(default)] to make deserialization from pre-1.13 servers rock-solid

Option<T> already handles missing JSON keys, but adding an explicit #[serde(default)] expresses that intention in the type definition and protects you from a future scenario where the server explicitly returns "numberOfEmbeddedDocuments": null (which would otherwise still work) and a deny_unknown_fields deserialization context (which would unexpectedly fail when the key is absent).
It also makes the intent clearer to downstream readers.

-/// Is `None` for Meilisearch servers older than 1.13.
-pub number_of_embedded_documents: Option<usize>,
+/// Is `None` for Meilisearch servers older than 1.13.
+#[serde(default)]
+pub number_of_embedded_documents: Option<usize>,
 ...
-/// Is `None` for Meilisearch servers older than 1.13.
-pub number_of_embeddings: Option<usize>,
+/// Is `None` for Meilisearch servers older than 1.13.
+#[serde(default)]
+pub number_of_embeddings: Option<usize>,

Minor, non-blocking.
(Remember to bump the crate’s semver major/minor as this is an API break for consumers.)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd4375 and 1ae5cc2.

📒 Files selected for processing (2)
  • src/client.rs (1 hunks)
  • src/indexes.rs (1 hunks)
⏰ 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). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (1)
src/client.rs (1)

1155-1158: No downstream usages of used_database_size found—no client code changes required

A global search for used_database_size only returns its declaration in src/client.rs (line 1157) with no other call-sites to update. Since there are no places treating this field as a plain usize, no additional pattern-matching or unwrapping adjustments are needed.

These three fields were added in 1.13. If you want to support older
servers, these fields need to be optional.

https://github.com/meilisearch/meilisearch/releases/tag/v1.13.0
@LukasKalbertodt LukasKalbertodt force-pushed the stats-for-older-servers branch from 1ae5cc2 to 6ba586e Compare July 28, 2025 11:39
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.76%. Comparing base (5dd4375) to head (6ba586e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #690   +/-   ##
=======================================
  Coverage   85.76%   85.76%           
=======================================
  Files          19       19           
  Lines        5860     5860           
=======================================
  Hits         5026     5026           
  Misses        834      834           

☔ 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.

@Mubelotix
Copy link
Collaborator

Hello, thank you for the PR.

If you want to support older servers

Sorry, but we do not. This is only one of many incompatibilities and it would require way too much work. If you are the owner of the outdated meilisearch instance I suggest you upgrade to the latest version. If you can't, just downgrade this library. Cargo supports having the same library multiple times with different versions if you need to handle multiple meilisearch versions in the same program

@Mubelotix Mubelotix closed this Jul 29, 2025
@martin-g
Copy link

Cargo supports having the same library multiple times with different versions if you need to handle multiple meilisearch versions in the same program

Can you explain more how this could work ?
How in my code I could say "use some_library version X" ?

@Mubelotix
Copy link
Collaborator

This probably needs a few changes to compile but it will give you an idea

[dependencies]
meilisearch-sdk = { package = "meilisearch-sdk", version = "0.29" }
old-meilisearch-sdk = { package = "meilisearch-sdk", version = "0.28" }
use meilisearch_sdk::Client;
use old_meilisearch_sdk::Client as OldClient;

let client = Client::new();
let old_client = OldClient::new();

@LukasKalbertodt
Copy link
Contributor Author

LukasKalbertodt commented Jul 29, 2025

Sorry, but we do not [support older servers]

Hu interesting, I didn't know that. You should probably adjust your README then. It says:

This package guarantees compatibility with version v1.x of Meilisearch, but some features may not be present.

Which to me reads "all 1.x versions". I think it should explicitly say that only the last version is supported or something like that.


Also, while I certainly understand the decision, it is a bit limiting for users. Especially since support for new features of Meili sometimes lands really late in this library. And when it finally lands, then the new (SDK) version might exclude many server versions, that's unfortunate. For example, the latest release of this library finally supports federated multi search (introduced in 1.10) and then immediately bumps the minimum supported version to 1.13.

Just as context: users of our software host it and Meilisearch themselves. So bumping our Meilisearch version requirement means it's a breaking change and admins cannot easily upgrade our software, but have to upgrade Meilisearch as well.

I don't expect to change your opinion on this, but just wanted to give you some insight why it's not optimal for us.

@Mubelotix
Copy link
Collaborator

I understand the confusion. I have checked and can confirm SDKs do not intend to support old versions. The readme is based on a template common to all SDKs so I can't clarify here right away. It already correctly links to the latest version though.

I suggest you keep using a fork of this repository if you find a way to suit your use case. We do not plan to refactor anything big in the near future, so you will probably be able to keep our changes flowing to your fork quite easily

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.

3 participants