Skip to content

fix: AttributeError in Folder.get_subfolders via _json_to_folders helper (#71)#73

Open
AmSach wants to merge 1 commit into
JensAstrup:developmentfrom
AmSach:fix/issue-71-get-subfolders-attribute-error
Open

fix: AttributeError in Folder.get_subfolders via _json_to_folders helper (#71)#73
AmSach wants to merge 1 commit into
JensAstrup:developmentfrom
AmSach:fix/issue-71-get-subfolders-attribute-error

Conversation

@AmSach

@AmSach AmSach commented Jun 5, 2026

Copy link
Copy Markdown

Summary

Fixes the AttributeError: 'OutlookAccount' object has no attribute '_json_to_folder' raised by Folder.get_subfolders() (and any other call into the deprecated classmethod helpers Folder._json_to_folder / Folder._json_to_folders).

Root cause

In src/pyOutlook/core/folder.py the two @classmethod helpers called the underlying FolderService methods as if they were class methods:

return FolderService._json_to_folders(account, json_value)

But FolderService._json_to_folder and FolderService._json_to_folders are instance methods (they use self.account). So the call bound account (an OutlookAccount) to self, and the next self.account._json_to_folder(...) line inside FolderService exploded with AttributeError — exactly the traceback in issue #71:

File ".../pyOutlook/core/folder.py", line 50, in _json_to_folders
    return FolderService._json_to_folders(account, json_value)
File ".../pyOutlook/services/folder.py", line 85, in _json_to_folders
    return [self._json_to_folder(folder) for folder in json_value['value']]
AttributeError: 'OutlookAccount' object has no attribute '_json_to_folder'

I reproduced this against the current development branch with a real (non-Mock) OutlookAccount-shaped object — the error matches the report.

Fix

Instantiate FolderService with the account and call the instance method, which matches the existing usage in FolderService.get / create / all:

from pyOutlook.services.folder import FolderService
service = FolderService(account)
return service._json_to_folders(json_value)

The same one-line pattern is applied to Folder._json_to_folder for symmetry.

Tests

  • Added matching updates to the two existing tests test_json_to_folder__delegates_to_folder_service and test_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.
  • Full test suite passes locally: python3 -m pytest tests/383 passed.

Verification

  • Reproduced the original AttributeError before the fix with a non-Mock account fixture.
  • After the fix, get_subfolders() returns the expected list of Folder instances built from the API response.

Linked issue

Fixes #71

Summary by CodeRabbit

  • Refactor
    • Internal restructuring of how folder services are instantiated and utilized within the core module. No changes to end-user functionality or public APIs.

…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).
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d5387145-4a28-410f-b9af-98b25cce29d6

📥 Commits

Reviewing files that changed from the base of the PR and between 80d703d and a454ef3.

📒 Files selected for processing (2)
  • src/pyOutlook/core/folder.py
  • tests/core/test_folder.py

Walkthrough

This PR fixes an AttributeError in Folder.get_subfolders() by changing how Folder._json_to_folder and Folder._json_to_folders delegate to FolderService. The implementation now instantiates FolderService(account) and calls instance methods instead of calling methods directly on the class, and tests are updated to verify the new pattern.

Changes

FolderService instantiation refactor

Layer / File(s) Summary
Folder service instantiation
src/pyOutlook/core/folder.py
Folder._json_to_folder and Folder._json_to_folders now instantiate FolderService(account) and delegate to instance methods instead of calling class methods.
Test updates for instantiation pattern
tests/core/test_folder.py
Tests refactored to verify FolderService construction with account and instance method calls with JSON payload, replacing prior class method call assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 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 clearly describes the main fix: resolving an AttributeError in the Folder.get_subfolders method by correcting the _json_to_folders helper.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #71: instantiating FolderService correctly, calling instance methods, and updating tests to match the new delegation pattern.
Out of Scope Changes check ✅ Passed All changes directly address the AttributeError fix in issue #71; no out-of-scope modifications are present in the source or test files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

AttributeError in get_subfolders() method

1 participant