Skip to content

Commit

Permalink
check if notification already exists to prevent duplicate insert atte…
Browse files Browse the repository at this point in the history
…mpts
  • Loading branch information
Kenneth Kehl committed Dec 2, 2024
1 parent 393add8 commit f3e412f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/dao/notifications_dao.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import timedelta

from flask import current_app
from sqlalchemy import asc, delete, desc, func, insert, or_, select, text, union, update
from sqlalchemy import asc, delete, desc, func, or_, select, text, union, update
from sqlalchemy.orm import joinedload
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.sql import functions
Expand Down Expand Up @@ -71,11 +71,11 @@ def dao_create_notification(notification):
# notify-api-742 remove phone numbers from db
notification.to = "1"
notification.normalised_to = "1"
stmt = (
insert(Notification).values(notification.serialize()).on_conflict_do_nothing()
)
db.session.execute(stmt)
db.session.commit()

stmt = select(Notification).where(id=notification.id)
result = db.session.execute(stmt).scalar()
if result is None:
db.session.add(notification)


def country_records_delivery(phone_prefix):
Expand Down

0 comments on commit f3e412f

Please sign in to comment.