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:
@@ -63,8 +63,7 @@ class CampaignService:
|
||||
is_active=data.get("is_active", True),
|
||||
)
|
||||
db.add(template)
|
||||
db.commit()
|
||||
db.refresh(template)
|
||||
db.flush()
|
||||
return template
|
||||
|
||||
def update_template(self, db: Session, template_id: int, data: dict) -> CampaignTemplate:
|
||||
@@ -72,14 +71,13 @@ class CampaignService:
|
||||
for field in ["name", "lead_type", "channel", "language", "subject_template", "body_template", "is_active"]:
|
||||
if field in data and data[field] is not None:
|
||||
setattr(template, field, data[field])
|
||||
db.commit()
|
||||
db.refresh(template)
|
||||
db.flush()
|
||||
return template
|
||||
|
||||
def delete_template(self, db: Session, template_id: int) -> bool:
|
||||
template = self.get_template_by_id(db, template_id)
|
||||
db.delete(template)
|
||||
db.commit()
|
||||
db.flush()
|
||||
return True
|
||||
|
||||
# --- Rendering ---
|
||||
@@ -143,7 +141,7 @@ class CampaignService:
|
||||
db.add(send)
|
||||
sends.append(send)
|
||||
|
||||
db.commit()
|
||||
db.flush()
|
||||
logger.info("Sent campaign %d to %d prospects", template_id, len(prospect_ids))
|
||||
return sends
|
||||
|
||||
|
||||
Reference in New Issue
Block a user