Skip to content

Fix bug with updating category -> group mapping after backend sync#23

Merged
wesm merged 4 commits intomainfrom
bug/category-remapping-sync
Oct 30, 2025
Merged

Fix bug with updating category -> group mapping after backend sync#23
wesm merged 4 commits intomainfrom
bug/category-remapping-sync

Conversation

@wesm
Copy link
Owner

@wesm wesm commented Oct 30, 2025

I had encountered a sporadic bug where Transfers (including credit card payments) would not be hidden from view no matter what on some application loads. The issue was that the category->group mapping (e.g. Credit Card Payment -> Transfer) would not get updated after pulling and syncing the backend's actual categories.

wesm and others added 4 commits October 30, 2025 13:44
…fresh categories

Bug: Transfers would not be filtered correctly (intermittent issue).

Root cause: DataManager.__init__() built category_to_group mapping once
from potentially stale config.yaml. When fetch_all_data() fetched fresh
categories from API and saved to config.yaml, the mapping was never
updated, causing transfers to not map to "Transfers" group.

Fix: After saving fresh categories to config.yaml, rebuild the
category_to_group mapping so transfers are correctly identified
and filtered.

Also moved inline imports to top of file per CLAUDE.md guidelines.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added 2 tests to prevent recurrence of intermittent transfer filtering bug:

1. test_category_mapping_refreshes_after_fetch:
   - Sets up stale config.yaml with incomplete categories
   - Initializes DataManager (loads stale mapping)
   - Calls fetch_all_data() (fetches fresh categories)
   - Verifies mapping is rebuilt with fresh data

2. test_categories_get_correct_group_in_dataframe:
   - Sets up config with wrong category-to-group mappings
   - Verifies DataFrame transactions get correct groups after refresh
   - Tests user-facing symptom (filtering relies on correct groups)

These tests will fail if category mapping is not refreshed after
fetching fresh categories from API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed type annotation for format_transaction_rows return type:
- Amount field (index 4) returns Union[str, Text], not just str
- Updated return type annotation to reflect this
- Added type: ignore comments in tests with proper assertions

All style checks now pass:
- ruff format --check moneyflow/ tests/
- ruff check moneyflow/ tests/
- pyright moneyflow/
- pyright tests/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Removed unused variable initial_group_count.

All style checks now pass:
- ruff format --check moneyflow/ tests/
- ruff check moneyflow/ tests/
- pyright moneyflow/
- pyright tests/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@wesm wesm merged commit d2e1eb4 into main Oct 30, 2025
6 checks passed
@wesm wesm deleted the bug/category-remapping-sync branch October 30, 2025 21:50
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.

1 participant