Skip to content

Address Book: prompt before overwriting duplicate contacts (#18) - #19

Merged
johanbeytell1 merged 1 commit into
mainfrom
arena/3532246a-python-projects
Oct 30, 2026
Merged

johanbeytell1 merged 1 commit into
mainfrom
arena/3532246a-python-projects

Conversation

@johanbeytell1

Copy link
Copy Markdown
Member

Summary

Fixes the silent contact overwrite reported in #18.

Beginner/14_address_book.py previously did contacts[name] = {...} unconditionally, so adding an existing name destroyed the saved contact with no warning. Adding a duplicate name now shows the existing contact's details and asks what to do:

  1. Overwrite the existing contact
  2. Keep both — save the new contact under an incremented name: Rani (2), Rani (3), ...
  3. Cancel — nothing is saved

Changes

  • Added next_available_name() to find the first free numbered suffix, handling names that already have one (e.g. adding Rani (2) suggests Rani (3)).
  • Added resolve_name() for duplicate handling; an existing contact is replaced only after explicit confirmation.
  • Phone/email are requested after the duplicate is resolved, so cancelling doesn't waste typing.
  • Trim whitespace from entered names and reject empty names.
  • README.md: noted the change under Latest Changes, added a step about checking for an existing name, and added Tip 3 explaining never to overwrite a contact silently — with credit to @SVarnavi06 for reporting the bug.

Testing

Ran the script against a real contacts.json and verified all three paths:

  • Overwrite: original entry replaced as confirmed.
  • Keep both: saved as rani (2), then rani (3) on the next duplicate.
  • Cancel: no changes written to disk.

Closes #18.

Contacts with an existing name are no longer silently replaced. Users can
overwrite, keep both (saving as 'Name (2)', 'Name (3)', ...), or cancel.
Update the README tips and latest changes, crediting @SVarnavi06.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@johanbeytell1
johanbeytell1 merged commit 95e38b0 into main Oct 30, 2026
@johanbeytell1
johanbeytell1 deleted the arena/3532246a-python-projects branch October 30, 2026 11:21
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.

Address Book silently overwrites existing contacts with duplicate names

1 participant