refactor: move transaction management from services to API endpoints
- Services now use db.flush() instead of db.commit() for database operations - API endpoints handle transaction commit after service calls - Remove db.rollback() from services (let exception handlers manage this) - Ensures consistent transaction boundaries at API layer This pattern gives API endpoints full control over when to commit, allowing for better error handling and potential multi-operation transactions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
6
app/api/v1/vendor/team.py
vendored
6
app/api/v1/vendor/team.py
vendored
@@ -150,6 +150,7 @@ def invite_team_member(
|
||||
email=invitation.email,
|
||||
role_name="staff",
|
||||
)
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
f"Invitation sent: {invitation.email} to {vendor.vendor_code} "
|
||||
@@ -189,6 +190,7 @@ def accept_invitation(acceptance: InvitationAccept, db: Session = Depends(get_db
|
||||
first_name=acceptance.first_name,
|
||||
last_name=acceptance.last_name,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
f"Invitation accepted: {result['user'].email} "
|
||||
@@ -272,6 +274,7 @@ def update_team_member(
|
||||
new_role_id=update_data.role_id,
|
||||
is_active=update_data.is_active,
|
||||
)
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
f"Team member updated: {user_id} in {vendor.vendor_code} "
|
||||
@@ -307,6 +310,7 @@ def remove_team_member(
|
||||
vendor = request.state.vendor
|
||||
|
||||
vendor_team_service.remove_team_member(db=db, vendor=vendor, user_id=user_id)
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
f"Team member removed: {user_id} from {vendor.vendor_code} "
|
||||
@@ -344,6 +348,8 @@ def bulk_remove_team_members(
|
||||
failed_count += 1
|
||||
errors.append({"user_id": user_id, "error": str(e)})
|
||||
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
f"Bulk remove completed: {success_count} removed, {failed_count} failed "
|
||||
f"in {vendor.vendor_code}"
|
||||
|
||||
Reference in New Issue
Block a user