Skip to content

Commit

Permalink
use on_conflict_do_nothing to prevent duplicate insert attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Dec 2, 2024
1 parent 6246684 commit 393add8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 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, or_, select, text, union, update
from sqlalchemy import asc, delete, desc, func, insert, 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,7 +71,11 @@ def dao_create_notification(notification):
# notify-api-742 remove phone numbers from db
notification.to = "1"
notification.normalised_to = "1"
db.session.add(notification)
stmt = (
insert(Notification).values(notification.serialize()).on_conflict_do_nothing()
)
db.session.execute(stmt)
db.session.commit()


def country_records_delivery(phone_prefix):
Expand Down

0 comments on commit 393add8

Please sign in to comment.