-
Notifications
You must be signed in to change notification settings - Fork 24
Description
π Bug Report: Inconsistent Field Naming - avatar vs imageUrl
Problem Description
There is a critical inconsistency in the backend codebase where user profile images are referenced using two different field names:
avatar(used in auth service and schemas)imageUrl(used in user service and schemas)
This inconsistency causes confusion, potential data corruption, and makes the API behavior unpredictable for frontend consumers.
Current State Analysis
Files using avatar:
backend/app/auth/schemas.py- Line 36:avatar: Optional[str] = Nonebackend/app/auth/service.py- Lines 96, 185, 186, 199: User creation and Google authbackend/app/groups/service.py- Lines 42, 46, 59: Group member enrichment
Files using imageUrl:
backend/app/user/schemas.py- Lines 10, 17:imageUrl: Optional[str] = Nonebackend/app/user/service.py- Line 38: Response mapping with fallback logicbackend/tests/user/- Multiple test files usingimageUrl
Fallback Logic Found:
# In user/service.py line 38
"imageUrl": user.get("imageUrl") or user.get("avatar")
# In groups/service.py line 42
"avatar": user.get("imageUrl") or user.get("avatar") if user else NoneDatabase Schema Documentation:
According to docs/nonrelational-database-schema.md, the intended field name is imageUrl.
Impact
- API Inconsistency: Different endpoints return user data with different field names
- Frontend Confusion: Clients don't know which field to expect
- Data Integrity: Users might have both fields populated with different values
- Maintenance Overhead: Fallback logic scattered across codebase
- Testing Issues: Tests use different field names
Proposed Solution
Standardize on imageUrl as the canonical field name across the entire backend, as specified in the database schema documentation.
Acceptance Criteria
π Phase 1: Code Standardization
- Auth Service: Update
auth/schemas.pyto useimageUrlinstead ofavatar - Auth Service: Update
auth/service.pyto useimageUrlin all user creation and update operations - Groups Service: Update
groups/service.pyto useimageUrlwhen enriching member data - Database Operations: Ensure all database queries and updates use
imageUrl - Response Models: Verify all API response models consistently use
imageUrl
π Phase 2: Database Migration
- Migration Script: Create a database migration script that:
- Identifies users with
avatarfield but noimageUrlfield - Copies
avatarvalues toimageUrlfield - Removes the deprecated
avatarfield from all user documents - Logs migration statistics and any conflicts found
- Identifies users with
- Backup Strategy: Document backup procedures before migration
- Rollback Plan: Create rollback script in case migration needs to be reversed
π Phase 3: Testing & Validation
- Unit Tests: Update all tests to use
imageUrlconsistently - Integration Tests: Verify API endpoints return consistent field names
- Migration Tests: Test migration script with sample data
- Backward Compatibility: Ensure no breaking changes for existing API consumers
π Phase 4: Documentation & Cleanup
- API Documentation: Update all API docs to reflect
imageUrlusage - Code Cleanup: Remove all fallback logic (
user.get("imageUrl") or user.get("avatar")) - Schema Validation: Add Pydantic validators if needed to ensure data consistency
- Migration Documentation: Document the migration process and results
Technical Requirements
Migration Script Specifications
The migration script should:
-
Pre-migration Validation:
- Count total users with
avatarfield - Count users with both
avatarandimageUrlfields - Identify potential conflicts (different values in both fields)
- Count total users with
-
Migration Process:
- For users with only
avatar: Copy toimageUrland removeavatar - For users with both fields: Keep
imageUrl(as it's the canonical field) and removeavatar - For users with neither: No action needed
- For users with only
-
Post-migration Validation:
- Verify no
avatarfields remain in user documents - Confirm all valid image URLs are preserved in
imageUrlfield - Generate migration report with statistics
- Verify no
-
Error Handling:
- Graceful handling of connection issues
- Rollback capability if migration fails
- Detailed logging of all operations
Files to Modify
backend/app/auth/schemas.py
backend/app/auth/service.py
backend/app/groups/service.py
backend/app/user/service.py (cleanup fallback logic)
backend/tests/auth/test_auth_routes.py
backend/tests/auth/test_auth_service.py
All other test files using avatar field
Migration Script Location
backend/migrations/
βββ migrate_avatar_to_imageurl.py
βββ rollback_avatar_migration.py
βββ README.md
Definition of Done
- All backend code uses
imageUrlconsistently - Database migration completed successfully
- All tests pass with updated field names
- API documentation updated
- Migration scripts tested and documented
- No breaking changes for existing API consumers
- Code review completed and approved
Priority: High π΄
This issue affects data consistency and API reliability across the entire application.
Estimated Effort: 2-3 days
- Day 1: Code standardization and testing
- Day 2: Migration script development and testing
- Day 3: Documentation, final testing, and deployment
Assignee: vraj patel (vrajpatel195)
Labels: bug, backend, database, gssoc25, level3
Metadata
Metadata
Assignees
Labels
Projects
Status