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:
@@ -117,7 +117,7 @@ class CodeQualityService:
|
||||
)
|
||||
db.add(violation)
|
||||
|
||||
db.commit()
|
||||
db.flush()
|
||||
db.refresh(scan)
|
||||
|
||||
logger.info(f"Scan completed: {scan.total_violations} violations found")
|
||||
@@ -268,7 +268,7 @@ class CodeQualityService:
|
||||
priority=priority,
|
||||
)
|
||||
db.add(assignment)
|
||||
db.commit()
|
||||
db.flush()
|
||||
|
||||
logger.info(f"Violation {violation_id} assigned to user {user_id}")
|
||||
return assignment
|
||||
@@ -297,7 +297,7 @@ class CodeQualityService:
|
||||
violation.resolved_by = resolved_by
|
||||
violation.resolution_note = resolution_note
|
||||
|
||||
db.commit()
|
||||
db.flush()
|
||||
logger.info(f"Violation {violation_id} resolved by user {resolved_by}")
|
||||
return violation
|
||||
|
||||
@@ -325,7 +325,7 @@ class CodeQualityService:
|
||||
violation.resolved_by = ignored_by
|
||||
violation.resolution_note = f"Ignored: {reason}"
|
||||
|
||||
db.commit()
|
||||
db.flush()
|
||||
logger.info(f"Violation {violation_id} ignored by user {ignored_by}")
|
||||
return violation
|
||||
|
||||
@@ -348,7 +348,7 @@ class CodeQualityService:
|
||||
violation_id=violation_id, user_id=user_id, comment=comment
|
||||
)
|
||||
db.add(comment_obj)
|
||||
db.commit()
|
||||
db.flush()
|
||||
|
||||
logger.info(f"Comment added to violation {violation_id} by user {user_id}")
|
||||
return comment_obj
|
||||
|
||||
Reference in New Issue
Block a user