mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
fix fragile filter approach
This commit is contained in:
@@ -244,18 +244,24 @@ def dao_get_failed_notification_count():
|
||||
|
||||
|
||||
def get_notification_with_personalisation(service_id, notification_id, key_type):
|
||||
filter_dict = {
|
||||
"Notification.service_id": service_id,
|
||||
"Notification.id": notification_id,
|
||||
}
|
||||
if key_type:
|
||||
filter_dict["Notification.key_type"] = key_type
|
||||
|
||||
stmt = (
|
||||
select(Notification)
|
||||
.where(**filter_dict)
|
||||
.where(
|
||||
Notification.service_id == service_id, Notification.id == notification_id
|
||||
)
|
||||
.options(joinedload(Notification.template))
|
||||
)
|
||||
if key_type:
|
||||
stmt = (
|
||||
select(Notification)
|
||||
.where(
|
||||
Notification.service_id == service_id,
|
||||
Notification.id == notification_id,
|
||||
Notification.key_type == key_type,
|
||||
)
|
||||
.options(joinedload(Notification.template))
|
||||
)
|
||||
return db.session.execute(stmt).scalars().one()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user