Skip to content

Add support for foreignKeys settings#1262

Open
addy790 wants to merge 2 commits into
meilisearch:mainfrom
addy790:add-foreign-keys-settings
Open

Add support for foreignKeys settings#1262
addy790 wants to merge 2 commits into
meilisearch:mainfrom
addy790:add-foreign-keys-settings

Conversation

@addy790

@addy790 addy790 commented Jul 1, 2026

Copy link
Copy Markdown

Pull Request

Related issue

Fixes #1258

What does this PR do?

This PR adds support for the experimental foreignKeys setting.

Changes

  • Added get_foreign_keys(), update_foreign_keys(), and reset_foreign_keys() methods to the Index class.
  • Added the foreign-keys path to Config.Paths.
  • Documented foreignKeys as a supported key in the update_settings() docstring.
  • Added tests in tests/settings/test_settings_foreign_keys_meilisearch.py covering get, update, update-to-null, and reset, using a new enable_foreign_keys fixture to opt in to the experimental feature.
  • Added get_foreign_keys_setting_1, update_foreign_keys_setting_1, and reset_foreign_keys_setting_1 code samples to .code-samples.meilisearch.yaml.

Testing

  • Ran the full test suite successfully (363 passed, 5 skipped).
  • Ran ruff check.
  • Ran ruff format.
  • Ran mypy.
  • Ran yamllint on the modified YAML file.

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
    -AI disclosure:
    I used ChatGPT to help understand the repository structure, contribution workflow, troubleshoot development issues, and review the implementation. I verified the generated suggestions, tested the implementation locally, and reviewed the final changes before submitting this PR.
  • 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

  • New Features
    • Added support for managing index foreign-key settings, including fetching, updating, clearing, and resetting.
    • Included new documentation guidance and runnable code samples for these foreign-key operations.
  • Tests
    • Added tests covering empty state, update persistence, clearing via null, and reset-to-default behavior.
    • Enabled the foreign-key feature during test execution and reverted it after tests complete.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3859ee4f-500d-483a-a7ef-ddc82f4b2277

📥 Commits

Reviewing files that changed from the base of the PR and between ea6b1b3 and 72673e5.

📒 Files selected for processing (2)
  • meilisearch/index.py
  • tests/settings/test_settings_foreign_keys_meilisearch.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • meilisearch/index.py
  • tests/settings/test_settings_foreign_keys_meilisearch.py

📝 Walkthrough

Walkthrough

Adds Meilisearch document relations support via a new foreignKeys index setting: a config path constant, three Index methods, matching YAML code samples, an experimental-feature fixture, and tests covering get, update, clear, and reset behavior.

Changes

Foreign keys settings support

Layer / File(s) Summary
Foreign keys config path
meilisearch/config.py
Adds foreign_keys = "foreign-keys" to Config.Paths.
Index foreign keys API methods
meilisearch/index.py
Adds the foreignKeys settings entry in the update-settings docs, plus get_foreign_keys(), update_foreign_keys(body), and reset_foreign_keys() on Index.
Foreign keys code samples
.code-samples.meilisearch.yaml
Adds get_foreign_keys_setting_1, update_foreign_keys_setting_1, and reset_foreign_keys_setting_1 samples.
Foreign keys tests and fixture
tests/conftest.py, tests/settings/test_settings_foreign_keys_meilisearch.py
Adds enable_foreign_keys to toggle the experimental feature, plus tests for get, update, update-to-none, and reset flows.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related issues

Poem

A rabbit hops with keys in paw,
Linking indexes, neat and raw.
Get, update, reset — hop, hop, hooray,
Foreign keys now dance today 🐇🔑

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title concisely states the main change: support for foreignKeys settings.
Linked Issues check ✅ Passed The PR adds the foreignKeys methods, updates settings docs, tests, and matching code samples requested by the issue.
Out of Scope Changes check ✅ Passed The changes stay focused on foreignKeys support and related docs, tests, and samples.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
meilisearch/index.py (1)

1210-1257: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

update_settings() docstring omits foreignKeys.

The PR objectives state the update_settings() docstring was updated to include foreignKeys as a supported key, but the supported-settings list here still doesn't mention it.

📝 Proposed fix
             - 'searchCutoffMs': Maximum search time in milliseconds
             - 'proximityPrecision': Precision for proximity ranking
             - 'localizedAttributes': Settings for localized attributes
+            - 'foreignKeys': Cross-index document relations (experimental)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@meilisearch/index.py` around lines 1210 - 1257, The update_settings()
docstring is missing the new supported settings key foreignKeys in the “body”
section. Update the supported-settings list in update_settings() to mention
foreignKeys alongside the other settings, keeping the rest of the docstring
consistent with the API docs and the existing symbols in Index.update_settings.
🧹 Nitpick comments (1)
tests/settings/test_settings_foreign_keys_meilisearch.py (1)

12-20: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing task-status assertion for consistency.

Unlike test_update_foreign_keys_to_none and test_reset_foreign_keys in this same file, this test doesn't assert update.status == "succeeded" after the update, so a silently-failed task would surface as a less informative assertion failure later.

✅ Proposed fix
     index = empty_index()
     response = index.update_foreign_keys(FOREIGN_KEYS)
-    index.wait_for_task(response.task_uid)
+    update = index.wait_for_task(response.task_uid)
+    assert update.status == "succeeded"
     get_keys = index.get_foreign_keys()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/settings/test_settings_foreign_keys_meilisearch.py` around lines 12 -
20, The foreign keys update test is missing the same task-status check used by
the other tests in this file. In test_update_foreign_keys, capture the result of
index.update_foreign_keys(FOREIGN_KEYS), wait for response.task_uid, then assert
the returned task/update status is succeeded before verifying get_foreign_keys
so failures surface clearly and consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@meilisearch/index.py`:
- Around line 1210-1257: The update_settings() docstring is missing the new
supported settings key foreignKeys in the “body” section. Update the
supported-settings list in update_settings() to mention foreignKeys alongside
the other settings, keeping the rest of the docstring consistent with the API
docs and the existing symbols in Index.update_settings.

---

Nitpick comments:
In `@tests/settings/test_settings_foreign_keys_meilisearch.py`:
- Around line 12-20: The foreign keys update test is missing the same
task-status check used by the other tests in this file. In
test_update_foreign_keys, capture the result of
index.update_foreign_keys(FOREIGN_KEYS), wait for response.task_uid, then assert
the returned task/update status is succeeded before verifying get_foreign_keys
so failures surface clearly and consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 783f5435-fcce-49e4-a183-c1a48f4ab4be

📥 Commits

Reviewing files that changed from the base of the PR and between 8330e28 and ea6b1b3.

📒 Files selected for processing (5)
  • .code-samples.meilisearch.yaml
  • meilisearch/config.py
  • meilisearch/index.py
  • tests/conftest.py
  • tests/settings/test_settings_foreign_keys_meilisearch.py

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.

[Meilisearch v1.48.0] Add document relations (experimental)

1 participant