Skip to content

Fix getDocument silently dropping a single string fields value - #2236

Merged
Strift merged 2 commits into
meilisearch:mainfrom
soroush5:fix/get-document-string-fields
Sep 16, 2026
Merged

Strift merged 2 commits into
meilisearch:mainfrom
soroush5:fix/get-document-string-fields

Conversation

@soroush5

@soroush5 soroush5 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

DocumentQuery.fields accepts an array of field names or a single field name, but getDocument only forwarded the array form. Passing a string (for example { fields: "title" }) replaced it with undefined, so the fields query parameter never reached the server and the full document came back instead of the selected field.

This change passes a string value through as-is and keeps joining arrays. Adds mocked-fetch tests covering the string form, the array form, and the omitted case.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed document retrieval so string-based field selections are correctly passed through and honored.
    • Document responses now return the requested fields, helping prevent unrequested data from being included.
  • Tests

    • Added coverage for retrieving a document with a single field specified as a string.
    • Verified that requesting the title field returns the expected title value.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 6f4f8760-4208-488d-8681-0977f1ca5727

📥 Commits

Reviewing files that changed from the base of the PR and between db3f557 and 6b748a6.

📒 Files selected for processing (2)
  • src/indexes.ts
  • tests/documents.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

getDocument now forwards string fields values. A test verifies that string field selection returns title and omits id.

Changes

Document fields query handling

Layer / File(s) Summary
Fields query serialization
src/indexes.ts, tests/documents.test.ts
getDocument passes non-array fields values through to the query. The test covers string field selection and verifies the returned document fields.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: strift

Merge Risk: ⚪ Minimal · up to 6b748

The change preserves string and array field selections, with corresponding test coverage, and is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving a single string value for getDocument fields.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


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

@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.15%. Comparing base (b738892) to head (6b748a6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2236   +/-   ##
=======================================
  Coverage   98.15%   98.15%           
=======================================
  Files          14       14           
  Lines         706      706           
  Branches      107      106    -1     
=======================================
  Hits          693      693           
  Misses         12       12           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Strift Strift added the bug Something isn't working label Sep 16, 2026

@Strift Strift left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks for yet another bug fix @soroush5 🙌

@Strift
Strift enabled auto-merge September 16, 2026 05:58
@Strift
Strift added this pull request to the merge queue Sep 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Sep 16, 2026
soroush5 and others added 2 commits September 16, 2026 16:45
DocumentQuery.fields accepts an array or a single field name, but
getDocument only forwarded the array form. A string was replaced with
undefined, so the fields query parameter never reached the server and
the full document came back instead of the requested field.
@Strift
Strift force-pushed the fix/get-document-string-fields branch from db3f557 to 6b748a6 Compare September 16, 2026 08:46
@Strift
Strift added this pull request to the merge queue Sep 16, 2026
Merged via the queue into meilisearch:main with commit df74c19 Sep 16, 2026
8 checks passed
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.

2 participants