Skip to content

Commit

Permalink
Fixes a few issues with project deletion (#2918)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Jan 31, 2023
1 parent 440e858 commit ab172fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/dispatch/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Project(Base):
organization_id = Column(Integer, ForeignKey(Organization.id))
organization = relationship("Organization")

dispatch_user_project = relationship(
"DispatchUserProject",
cascade="all, delete-orphan",
)

@hybrid_property
def slug(self):
return slugify(self.name)
Expand Down
12 changes: 11 additions & 1 deletion src/dispatch/service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@ def delete_service(*, db_session: Session = Depends(get_db), service_id: Primary
status_code=status.HTTP_404_NOT_FOUND,
detail=[{"msg": "A service with this id does not exist."}],
)
delete(db_session=db_session, service_id=service_id)
try:
delete(db_session=db_session, service_id=service_id)
except IntegrityError:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[
{
"msg": "Unable to delete service because it is referenced by an incident `Role`. Remove this reference before deletion."
}
],
)

0 comments on commit ab172fd

Please sign in to comment.