Skip to content

Commit

Permalink
fix: org creation exception handling, org id rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 26, 2023
1 parent 8296fa7 commit 4a17e71
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/backend/app/organization/organization_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ async def create_organization(
f"{settings.S3_DOWNLOAD_ROOT}/{settings.S3_BUCKET_NAME}{logo_path}"
)
db.commit()

except Exception as e:
log.error(e)
log.exception(e)
log.debug("Rolling back changes to db organization")
# Rollback any changes
db.rollback()
# Delete the failed organization entry
if db_organization:
log.debug(f"Deleting created organisation ID {db_organization.id}")
db.delete(db_organization)
db.commit()
raise HTTPException(
status_code=400, detail=f"Error creating organization: {e}"
) from e
Expand Down

0 comments on commit 4a17e71

Please sign in to comment.