Skip to content

fix: return attribute value instead of attribute name in FieldDistribution.__getattr__ (closes #1094)#1236

Open
botbikamordehai2-sketch wants to merge 1 commit into
meilisearch:mainfrom
botbikamordehai2-sketch:fix/issue-1094-1779956419
Open

fix: return attribute value instead of attribute name in FieldDistribution.__getattr__ (closes #1094)#1236
botbikamordehai2-sketch wants to merge 1 commit into
meilisearch:mainfrom
botbikamordehai2-sketch:fix/issue-1094-1779956419

Conversation

@botbikamordehai2-sketch
Copy link
Copy Markdown

@botbikamordehai2-sketch botbikamordehai2-sketch commented May 28, 2026

What

The __getattr__ method in FieldDistribution was returning the attribute name (a string) instead of the actual attribute value. This caused stats.numberOfDocuments to return the string "numberOfDocuments" rather than the integer value.

Fix

Changed return attr to return self.__dict[attr] in FieldDistribution.__getattr__, and updated the return type annotation from str to int to reflect the actual value type stored in the distribution dict.

Closes #1094

Summary

Fixed FieldDistribution.__getattr__ to return the actual attribute value from the internal dictionary instead of returning the attribute name string. This makes index statistics accessible through the dataclass API.

Changes

meilisearch/models/index.py:

  • Modified FieldDistribution.__getattr__ to return self.__dict[attr] instead of attr
  • Updated return type annotation from str to int to reflect the actual value type

Impact

Accessing statistics properties through FieldDistribution now correctly returns numeric values (e.g., stats.numberOfDocuments returns an integer count) instead of the property name string itself.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

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: 94d38bc5-5fde-4af9-abbc-94b2bfd68194

📥 Commits

Reviewing files that changed from the base of the PR and between ada25db and 9372a7f.

📒 Files selected for processing (1)
  • meilisearch/models/index.py

📝 Walkthrough

Walkthrough

The FieldDistribution.__getattr__ method in meilisearch/models/index.py is corrected to return the actual integer value from its internal distribution dictionary when an attribute exists, instead of returning the attribute name string. The error behavior for missing attributes is preserved.

Changes

FieldDistribution attribute value access fix

Layer / File(s) Summary
FieldDistribution.getattr return value correction
meilisearch/models/index.py
__getattr__ now returns the mapped integer value from the distribution dictionary when the requested attribute exists, instead of returning the attribute name string. Missing attribute fallback still raises AttributeError.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A rabbit hops through code so neat,
Fixing values, making stats complete!
No more names where numbers should shine—
Dictionary lookups now work divine! ✨

🚥 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%. 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 pull request title clearly and specifically describes the main change: fixing FieldDistribution.getattr to return attribute values instead of attribute names, and references the closed issue #1094.
Linked Issues check ✅ Passed The pull request successfully addresses the core requirement from issue #1094: fixing getattr to return stored attribute values instead of attribute names in the stats dataclass.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the FieldDistribution.getattr behavior as required by issue #1094; no unrelated or out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

Stats of IndexStats Class not Accessible

1 participant