Fix #134: Add validation for duplicate profile names#175
Open
Vaibhavee89 wants to merge 1 commit intojamiepine:mainfrom
Open
Fix #134: Add validation for duplicate profile names#175Vaibhavee89 wants to merge 1 commit intojamiepine:mainfrom
Vaibhavee89 wants to merge 1 commit intojamiepine:mainfrom
Conversation
- Add validation in create_profile() to check for existing names before insert - Add validation in update_profile() to prevent renaming to duplicate names - Improve error handling in API endpoints with user-friendly messages - Add comprehensive test suite for duplicate name validation - Update CHANGELOG.md with fix details This fix prevents database constraint violations and provides clear error messages when users attempt to create or update profiles with names that already exist in the database.
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
This PR fixes issue #134 where users encountered database errors when trying to save profiles with duplicate names.
Changes
Backend Validation (
backend/profiles.py)create_profile()to check for existing profile names before database insertupdate_profile()to prevent renaming to duplicate names (while allowing profiles to keep their own name)ValueErrorwith clear message: "A profile with the name 'X' already exists. Please choose a different name."API Error Handling (
backend/main.py)create_profileendpoint with explicit ValueError catchingupdate_profileendpoint (previously had no error handling)Testing (
backend/tests/test_profile_duplicate_names.py)Documentation
CHANGELOG.mdwith fix detailsBefore This Fix
UNIQUE constraint failed: profiles.nameAfter This Fix
A profile with the name 'Test Profile' already exists. Please choose a different name.Testing
Manual Testing
Verified that:
Automated Tests
Run the test suite:
cd backend pip install pytest pytest-asyncio pytest tests/test_profile_duplicate_names.py -vChecklist
Related Issues
Closes #134
Screenshots
The original issue included a screenshot of the database error. After this fix, users will see a clear message instead.