Prepare to stop inserting NotificationHistory at the time of inserting a notificaiton.

Need to remove foreign key to complaints.
Make sure if getting Notification.id we look to both tables.
This commit is contained in:
Rebecca Law
2019-05-21 16:08:18 +01:00
parent bde1e751ad
commit 3374e03ce9
4 changed files with 34 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ from notifications_utils.statsd_decorators import statsd
from notifications_utils.timezones import convert_utc_to_bst
from sqlalchemy import (desc, func, asc)
from sqlalchemy.orm import joinedload
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.sql import functions
from sqlalchemy.sql.expression import case
from sqlalchemy.dialects.postgresql import insert
@@ -585,9 +586,16 @@ def dao_get_notification_by_reference(reference):
@statsd(namespace="dao")
def dao_get_notification_history_by_reference(reference):
return NotificationHistory.query.filter(
NotificationHistory.reference == reference
).one()
try:
# This try except is necessary because in test keys and research mode does not create notification history.
# Otherwise we could just search for the NotificationHistory object
return Notification.query.filter(
Notification.reference == reference
).one()
except NoResultFound:
return NotificationHistory.query.filter(
NotificationHistory.reference == reference
).one()
@statsd(namespace="dao")