[PR #6971] [WIP] Fix: new categories always rejected as duplicates #6854

Closed
opened 2026-02-28 21:33:37 -06:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/actualbudget/actual/pull/6971

State: closed
Merged: No


Summary

  • Fixed a bug in useSaveCategoryMutation where creating a new category in a group that already contains categories always triggers the "already exists" error, regardless of the name entered
  • The duplicate name check was unconditionally returning true for new categories (id === 'new') instead of comparing names
  • Now properly checks if the name actually matches an existing category before rejecting

Before

const exists = categoriesInGroup.some(c =>
  category.id === 'new'
    ? true  // always returns true — any existing category = "duplicate"
    : c.id !== category.id &&
      c.name.toUpperCase() === category.name.toUpperCase(),
);

After

const exists = categoriesInGroup.some(
  c =>
    (category.id === 'new' || c.id !== category.id) &&
    c.name.toUpperCase() === category.name.toUpperCase(),
);

Test plan

  • Create a new budget with default categories
  • Try adding a new category (e.g., "Pluto") to any existing group → previously failed with "already exists", now works correctly
  • Verify that actual duplicate names are still rejected
  • Verify renaming a category to a name that already exists in the group is still rejected

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/actualbudget/actual/pull/6971 **State:** closed **Merged:** No --- ## Summary - Fixed a bug in `useSaveCategoryMutation` where creating a new category in a group that already contains categories always triggers the "already exists" error, regardless of the name entered - The duplicate name check was unconditionally returning `true` for new categories (`id === 'new'`) instead of comparing names - Now properly checks if the name actually matches an existing category before rejecting ## Before ```js const exists = categoriesInGroup.some(c => category.id === 'new' ? true // always returns true — any existing category = "duplicate" : c.id !== category.id && c.name.toUpperCase() === category.name.toUpperCase(), ); ``` ## After ```js const exists = categoriesInGroup.some( c => (category.id === 'new' || c.id !== category.id) && c.name.toUpperCase() === category.name.toUpperCase(), ); ``` ## Test plan - [x] Create a new budget with default categories - [x] Try adding a new category (e.g., "Pluto") to any existing group → previously failed with "already exists", now works correctly - [x] Verify that actual duplicate names are still rejected - [x] Verify renaming a category to a name that already exists in the group is still rejected 🤖 Generated with [Claude Code](https://claude.com/claude-code)
GiteaMirror added the pull-request label 2026-02-28 21:33:37 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#6854