-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
Snapshot creation logic is duplicated in two places, violating DRY and the repository pattern. Both locations use direct db.add() instead of a repository method.
Steps to Reproduce
- Open
backend/core/user_manager.py:64-74 - Open
backend/services/profile_service.py:70-79 - Compare the snapshot creation code - nearly identical
Expected Behavior
Snapshot creation should be a single method in UserProfileRepository:
await repo.create_snapshot(profile)
Actual Behavior
Two separate locations create snapshots with duplicated code:
Location 1: core/user_manager.py:64-74 (registration)
- Creates
UserProfileSnapshotwith hardcodedversion=1 - Uses
db.add(snapshot)directly
Location 2: services/profile_service.py:70-79 (profile update)
- Creates
UserProfileSnapshotwithupdated_profile.version - Uses
self.db.add(snapshot)directly
Root Cause
- Service layer (
profile_service.py) bypasses repository for snapshot creation user_manager.pyhas no access to repositories (fastapi-users hook limitation)- No
create_snapshot()method exists inUserProfileRepository
Possible Solutions
-
Option A: Add
create_snapshot()toUserProfileRepository- Add method to
repositories/user_profile_repository.py - Update
profile_service.pyto useself.repo.create_snapshot() - Update
user_manager.pyto instantiate repo and use it
- Add method to
-
Option B: Create standalone snapshot utility
- Create
utils/snapshot.pywithcreate_snapshot(db, profile)function - Both locations import and use the utility
- Less pure but simpler given fastapi-users constraints
- Create
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels