Repository navigation
Address Book: prompt before overwriting duplicate contacts (#18) - #19
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the silent contact overwrite reported in #18.
Beginner/14_address_book.pypreviously didcontacts[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:Rani (2),Rani (3), ...Changes
next_available_name()to find the first free numbered suffix, handling names that already have one (e.g. addingRani (2)suggestsRani (3)).resolve_name()for duplicate handling; an existing contact is replaced only after explicit confirmation.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.jsonand verified all three paths:rani (2), thenrani (3)on the next duplicate.Closes #18.