Getting the IntegrityErrors to be OK if the data already exists in the

DB.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-12-23 11:17:51 -05:00
parent d5e1008b19
commit 46ec1aafa8
3 changed files with 37 additions and 24 deletions

View File

@@ -65,6 +65,12 @@ def dao_get_last_date_template_was_used(template_id, service_id):
return last_date
def dao_notification_exists(notification_id) -> bool:
stmt = select(Notification).where(Notification.id == notification_id)
result = db.session.execute(stmt).scalar()
return result is not None
@autocommit
def dao_create_notification(notification):
if not notification.id:
@@ -86,9 +92,7 @@ def dao_create_notification(notification):
notification.normalised_to = "1"
# notify-api-1454 insert only if it doesn't exist
stmt = select(Notification).where(Notification.id == notification.id)
result = db.session.execute(stmt).scalar()
if result is None:
if not dao_notification_exists(notification.id):
db.session.add(notification)