fix: AttributeError in Folder.get_subfolders via _json_to_folders helper (#71)#73
Conversation
…trup#71) Folder._json_to_folder and Folder._json_to_folders were calling FolderService._json_to_folder / _json_to_folders as class methods and passing 'account' as the first argument. But those are instance methods on FolderService — they expect 'self' (the FolderService instance) as the first argument. The actual OutlookAccount (self.account) was being used as 'self', so when the implementation tried to call self.account._json_to_folder(...) it raised: AttributeError: 'OutlookAccount' object has no attribute '_json_to_folder' This broke Folder.get_subfolders() and any other Folder method that used the _json_to_folders classmethod helper. Fix: instantiate FolderService with the account and call the instance method on it, matching how FolderService._json_to_folder is defined and called elsewhere (e.g. FolderService.get/create/all). Tests: the two existing 'delegates to FolderService' tests patched FolderService and asserted on the unbound class method; they have been updated to patch the FolderService class, assert it was instantiated with the account, and assert the instance method was called with just json_value. Full test suite passes (383 tests).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR fixes an ChangesFolderService instantiation refactor
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Summary
Fixes the
AttributeError: 'OutlookAccount' object has no attribute '_json_to_folder'raised byFolder.get_subfolders()(and any other call into the deprecated classmethod helpersFolder._json_to_folder/Folder._json_to_folders).Root cause
In
src/pyOutlook/core/folder.pythe two@classmethodhelpers called the underlyingFolderServicemethods as if they were class methods:But
FolderService._json_to_folderandFolderService._json_to_foldersare instance methods (they useself.account). So the call boundaccount(anOutlookAccount) toself, and the nextself.account._json_to_folder(...)line insideFolderServiceexploded withAttributeError— exactly the traceback in issue #71:I reproduced this against the current
developmentbranch with a real (non-Mock)OutlookAccount-shaped object — the error matches the report.Fix
Instantiate
FolderServicewith theaccountand call the instance method, which matches the existing usage inFolderService.get/create/all:The same one-line pattern is applied to
Folder._json_to_folderfor symmetry.Tests
test_json_to_folder__delegates_to_folder_serviceandtest_json_to_folders__delegates_to_folder_service— they previously asserted on the unbound class method (which is what the old, broken code did), so they need to assert on the instance method now.python3 -m pytest tests/→ 383 passed.Verification
get_subfolders()returns the expected list ofFolderinstances built from the API response.Linked issue
Fixes #71
Summary by CodeRabbit