refactor(prospecting): migrate SVC-006 transaction control to endpoint level
Some checks failed
Some checks failed
Move db.commit() from services to API endpoints and Celery tasks. Services now use db.flush() only; endpoints own the transaction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -137,8 +137,7 @@ class ProspectService:
|
||||
)
|
||||
db.add(contact)
|
||||
|
||||
db.commit()
|
||||
db.refresh(prospect)
|
||||
db.flush()
|
||||
logger.info("Created prospect: %s (channel=%s)", prospect.display_name, channel)
|
||||
return prospect
|
||||
|
||||
@@ -161,7 +160,7 @@ class ProspectService:
|
||||
db.add(prospect)
|
||||
created += 1
|
||||
|
||||
db.commit()
|
||||
db.flush()
|
||||
logger.info("Bulk import: %d created, %d skipped", created, skipped)
|
||||
return created, skipped
|
||||
|
||||
@@ -178,14 +177,13 @@ class ProspectService:
|
||||
tags = json.dumps(tags)
|
||||
prospect.tags = tags
|
||||
|
||||
db.commit()
|
||||
db.refresh(prospect)
|
||||
db.flush()
|
||||
return prospect
|
||||
|
||||
def delete(self, db: Session, prospect_id: int) -> bool:
|
||||
prospect = self.get_by_id(db, prospect_id)
|
||||
db.delete(prospect)
|
||||
db.commit()
|
||||
db.flush()
|
||||
logger.info("Deleted prospect: %d", prospect_id)
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user