fix: return attribute value instead of attribute name in FieldDistribution.__getattr__ (closes #1094)#1236
Conversation
…ution.__getattr__ (closes meilisearch#1094)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesFieldDistribution attribute value access fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
What
The
__getattr__method inFieldDistributionwas returning the attribute name (a string) instead of the actual attribute value. This causedstats.numberOfDocumentsto return the string"numberOfDocuments"rather than the integer value.Fix
Changed
return attrtoreturn self.__dict[attr]inFieldDistribution.__getattr__, and updated the return type annotation fromstrtointto 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:
FieldDistribution.__getattr__to returnself.__dict[attr]instead ofattrstrtointto reflect the actual value typeImpact
Accessing statistics properties through
FieldDistributionnow correctly returns numeric values (e.g.,stats.numberOfDocumentsreturns an integer count) instead of the property name string itself.