[PR #6878] [MERGED] Avoid duplicate category import errors in YNAB5 importer #48614

Closed
opened 2026-04-26 10:32:00 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/6878
Author: @StephenBrown2
Created: 2/5/2026
Status: Merged
Merged: 2/6/2026
Merged by: @youngcw

Base: masterHead: push-qmntmlzvpspm


📝 Commits (2)

  • 7e518a5 avoid duplicate category import errors
  • 2c8d452 Add release notes file

📊 Changes

2 files changed (+90 additions, -51 deletions)

View changed files

📝 packages/loot-core/src/server/importers/ynab5.ts (+84 -51)
upcoming-release-notes/6878.md (+6 -0)

📄 Description

Summary

Refactors the YNAB5 category import retry logic to avoid duplicate category/group import errors by extracting clean helper functions with proper unique name generation, replacing the previous inline retry loops that mutated input data.

Found when importing the demo budget file, and resulting in uncaught errors, which also prevented me from switching the file without clearing the browser data:

Screenshot_2026-02-05_16-50-08

With these changes, no uncaught errors, and the budget categories and goals show up correctly, hidden:

image

What

  • Extracted createCategoryGroupWithUniqueName and createCategoryWithUniqueName helper functions from the inline retry loops in importCategories
  • Moved the MAX_RETRY constant to module scope (consolidated to a single value of 20) instead of declaring it multiple times with inconsistent values (10 and 50)
  • Added a guard clause to skip category creation when groupId is undefined (for skipped groups like Internal Master Category, Credit Card Payments, Hidden Categories, and Income)
  • Changed the duplicate name suffix convention from -N (e.g. Groceries-1) to (N) (e.g. Groceries (1)), with hidden categories/groups automatically receiving a (hidden) suffix

Why

  • The previous retry logic mutated the original group.name / cat.name properties directly (group.name = origName + '-' + count.toString()), which could cause unintended side effects on the input data
  • MAX_RETRY was declared independently in three separate places with inconsistent values, making it hard to maintain
  • When a category group was skipped (internal/income/credit cards), groupId remained undefined, but the code still attempted to create child categories under it — leading to potential errors

How

  • Extracted the retry-with-rename pattern into two dedicated async helper functions defined inside importCategories, each building candidate names locally without mutating input data
  • Each helper uses a count starting at 0, where count === 0 uses the base name and count > 0 appends (N)
  • Hidden groups/categories get a (hidden) suffix appended to the base name before retry numbering
  • Hoisted MAX_RETRY = 20 to module scope and removed all duplicate declarations
  • Added if (!groupId) { break; } guard in the category creation switch case to safely skip orphaned categories

AI Generated

Yes, this PR was created with assistance from AI.


Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 28 14.55 MB → 14.56 MB (+8.06 kB) +0.05%
loot-core 1 5.86 MB → 5.86 MB (+635 B) +0.01%
api 1 4.39 MB → 4.39 MB (+559 B) +0.01%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
28 14.55 MB → 14.56 MB (+8.06 kB) +0.05%
Changeset
File Δ Size
locale/pt-BR.json 📈 +8.06 kB (+5.50%) 146.51 kB → 154.57 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
static/js/pt-BR.js 146.51 kB → 154.57 kB (+8.06 kB) +5.50%

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
static/js/index.js 9.31 MB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 12.94 kB 0%
static/js/workbox-window.prod.es5.js 5.64 kB 0%
static/js/da.js 106.62 kB 0%
static/js/de.js 178.39 kB 0%
static/js/en-GB.js 7.18 kB 0%
static/js/en.js 164.16 kB 0%
static/js/es.js 173.83 kB 0%
static/js/fr.js 179.62 kB 0%
static/js/it.js 171.44 kB 0%
static/js/nb-NO.js 157.23 kB 0%
static/js/nl.js 106.65 kB 0%
static/js/pl.js 88.64 kB 0%
static/js/ru.js 106.97 kB 0%
static/js/sv.js 78.2 kB 0%
static/js/th.js 182.35 kB 0%
static/js/uk.js 215.11 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 120.54 kB 0%
static/js/ReportRouter.js 1.11 MB 0%
static/js/narrow.js 640.46 kB 0%
static/js/TransactionList.js 105.97 kB 0%
static/js/wide.js 160.07 kB 0%
static/js/AppliedFilters.js 9.71 kB 0%
static/js/usePayeeRuleCounts.js 11.79 kB 0%
static/js/useTransactionBatchActions.js 13.23 kB 0%
static/js/FormulaEditor.js 1.04 MB 0%

loot-core

Total

Files count Total bundle size % Changed
1 5.86 MB → 5.86 MB (+635 B) +0.01%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/importers/ynab5.ts 📈 +635 B (+2.20%) 28.13 kB → 28.75 kB
View detailed bundle breakdown

Added

Asset File Size % Changed
kcab.worker.BSvyjHTd.js 0 B → 5.86 MB (+5.86 MB) -

Removed

Asset File Size % Changed
kcab.worker.CiaHZEop.js 5.86 MB → 0 B (-5.86 MB) -100%

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged
No assets were unchanged


api

Total

Files count Total bundle size % Changed
1 4.39 MB → 4.39 MB (+559 B) +0.01%
Changeset
File Δ Size
src/server/importers/ynab5.ts 📈 +559 B (+2.17%) 25.14 kB → 25.69 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
bundle.api.js 4.39 MB → 4.39 MB (+559 B) +0.01%

Smaller
No assets were smaller

Unchanged
No assets were unchanged


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/6878 **Author:** [@StephenBrown2](https://github.com/StephenBrown2) **Created:** 2/5/2026 **Status:** ✅ Merged **Merged:** 2/6/2026 **Merged by:** [@youngcw](https://github.com/youngcw) **Base:** `master` ← **Head:** `push-qmntmlzvpspm` --- ### 📝 Commits (2) - [`7e518a5`](https://github.com/actualbudget/actual/commit/7e518a5e2aaebf1a0a334338cbc13061c4a74e96) avoid duplicate category import errors - [`2c8d452`](https://github.com/actualbudget/actual/commit/2c8d45201c5fbe67f9dd894279d802e88f462a60) Add release notes file ### 📊 Changes **2 files changed** (+90 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `packages/loot-core/src/server/importers/ynab5.ts` (+84 -51) ➕ `upcoming-release-notes/6878.md` (+6 -0) </details> ### 📄 Description ## Summary Refactors the YNAB5 category import retry logic to avoid duplicate category/group import errors by extracting clean helper functions with proper unique name generation, replacing the previous inline retry loops that mutated input data. Found when importing the [demo budget file](https://github.com/actualbudget/actual/blob/master/packages/desktop-client/e2e/data/ynab5-demo-budget.json), and resulting in uncaught errors, which also prevented me from switching the file without clearing the browser data: <img width="412" height="873" alt="Screenshot_2026-02-05_16-50-08" src="https://github.com/user-attachments/assets/a5406f47-7a89-4af7-b103-a25147c47e3f" /> With these changes, no uncaught errors, and the budget categories and goals show up correctly, hidden: <img width="1287" height="871" alt="image" src="https://github.com/user-attachments/assets/686407bb-00f3-4fb1-89e4-ed90d3f6f51d" /> ## What - Extracted `createCategoryGroupWithUniqueName` and `createCategoryWithUniqueName` helper functions from the inline retry loops in `importCategories` - Moved the `MAX_RETRY` constant to module scope (consolidated to a single value of `20`) instead of declaring it multiple times with inconsistent values (`10` and `50`) - Added a guard clause to skip category creation when `groupId` is undefined (for skipped groups like Internal Master Category, Credit Card Payments, Hidden Categories, and Income) - Changed the duplicate name suffix convention from `-N` (e.g. `Groceries-1`) to `(N)` (e.g. `Groceries (1)`), with hidden categories/groups automatically receiving a `(hidden)` suffix ## Why - The previous retry logic mutated the original `group.name` / `cat.name` properties directly (`group.name = origName + '-' + count.toString()`), which could cause unintended side effects on the input data - `MAX_RETRY` was declared independently in three separate places with inconsistent values, making it hard to maintain - When a category group was skipped (internal/income/credit cards), `groupId` remained `undefined`, but the code still attempted to create child categories under it — leading to potential errors ## How - Extracted the retry-with-rename pattern into two dedicated `async` helper functions defined inside `importCategories`, each building candidate names locally without mutating input data - Each helper uses a `count` starting at `0`, where `count === 0` uses the base name and `count > 0` appends ` (N)` - Hidden groups/categories get a ` (hidden)` suffix appended to the base name before retry numbering - Hoisted `MAX_RETRY = 20` to module scope and removed all duplicate declarations - Added `if (!groupId) { break; }` guard in the category creation `switch` case to safely skip orphaned categories ### AI Generated Yes, this PR was created with assistance from AI. <!--- actual-bot-sections ---> <hr /> <!--- bundlestats-action-comment key:combined start ---> ### Bundle Stats Bundle | Files count | Total bundle size | % Changed ------ | ----------- | ----------------- | --------- desktop-client | 28 | 14.55 MB → 14.56 MB (+8.06 kB) | +0.05% loot-core | 1 | 5.86 MB → 5.86 MB (+635 B) | +0.01% api | 1 | 4.39 MB → 4.39 MB (+559 B) | +0.01% <details> <summary>View detailed bundle stats</summary> #### desktop-client **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 28 | 14.55 MB → 14.56 MB (+8.06 kB) | +0.05% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `locale/pt-BR.json` | 📈 +8.06 kB (+5.50%) | 146.51 kB → 154.57 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- static/js/pt-BR.js | 146.51 kB → 154.57 kB (+8.06 kB) | +5.50% **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- static/js/index.js | 9.31 MB | 0% static/js/indexeddb-main-thread-worker-e59fee74.js | 12.94 kB | 0% static/js/workbox-window.prod.es5.js | 5.64 kB | 0% static/js/da.js | 106.62 kB | 0% static/js/de.js | 178.39 kB | 0% static/js/en-GB.js | 7.18 kB | 0% static/js/en.js | 164.16 kB | 0% static/js/es.js | 173.83 kB | 0% static/js/fr.js | 179.62 kB | 0% static/js/it.js | 171.44 kB | 0% static/js/nb-NO.js | 157.23 kB | 0% static/js/nl.js | 106.65 kB | 0% static/js/pl.js | 88.64 kB | 0% static/js/ru.js | 106.97 kB | 0% static/js/sv.js | 78.2 kB | 0% static/js/th.js | 182.35 kB | 0% static/js/uk.js | 215.11 kB | 0% static/js/resize-observer.js | 18.37 kB | 0% static/js/BackgroundImage.js | 120.54 kB | 0% static/js/ReportRouter.js | 1.11 MB | 0% static/js/narrow.js | 640.46 kB | 0% static/js/TransactionList.js | 105.97 kB | 0% static/js/wide.js | 160.07 kB | 0% static/js/AppliedFilters.js | 9.71 kB | 0% static/js/usePayeeRuleCounts.js | 11.79 kB | 0% static/js/useTransactionBatchActions.js | 13.23 kB | 0% static/js/FormulaEditor.js | 1.04 MB | 0% </div> </details> --- #### loot-core **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 5.86 MB → 5.86 MB (+635 B) | +0.01% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/server/importers/ynab5.ts` | 📈 +635 B (+2.20%) | 28.13 kB → 28.75 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.BSvyjHTd.js | 0 B → 5.86 MB (+5.86 MB) | - **Removed** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.CiaHZEop.js | 5.86 MB → 0 B (-5.86 MB) | -100% **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> --- #### api **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 4.39 MB → 4.39 MB (+559 B) | +0.01% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `src/server/importers/ynab5.ts` | 📈 +559 B (+2.17%) | 25.14 kB → 25.69 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- bundle.api.js | 4.39 MB → 4.39 MB (+559 B) | +0.01% **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> </details> <!--- bundlestats-action-comment key:combined end ---> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-26 10:32:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#48614