Fix out-of-date rows in ft_notification_status

This can happen in the following scenario (primarily for letters):

1. A service has a mixture of "delivered" and "sending" letters,
which the status task aggregates into two rows:

  sending | 123
  delivered | 456

2. After the 7 day retention has passed, only the "delivered" letters
will be archived [^1].

3. The status task now looks at the history table [^2], which means
it only sees the "delivered" letters.

4. The "sending" letters are eventually "delivered" and archived (before
the 10 day aggregation cutoff).

5. But the status aggregation task doesn't run.

This commit fixes (5).

[^1]: https://github.com/alphagov/notifications-api/pull/3063
[^2]: f87ebb094d/app/dao/fact_notification_status_dao.py (L51)
This commit is contained in:
Ben Thorner
2022-05-10 11:14:59 +01:00
parent 867e8fbce3
commit ed379a3724
2 changed files with 33 additions and 10 deletions

View File

@@ -48,6 +48,7 @@ from app.models import (
NotificationHistory,
)
from tests.app.db import (
create_ft_notification_status,
create_job,
create_notification,
create_notification_history,
@@ -1742,3 +1743,13 @@ def test_get_service_ids_with_notifications_on_date_respects_gmt_bst(
create_notification(template=sample_template, created_at=created_at_utc)
service_ids = get_service_ids_with_notifications_on_date(SMS_TYPE, date_to_check)
assert len(service_ids) == expected_count
def test_get_service_ids_with_notifications_on_date_checks_ft_status(
sample_template,
):
create_notification(template=sample_template, created_at='2022-01-01T09:30')
create_ft_notification_status(template=sample_template, bst_date='2022-01-02')
assert len(get_service_ids_with_notifications_on_date(SMS_TYPE, date(2022, 1, 1))) == 1
assert len(get_service_ids_with_notifications_on_date(SMS_TYPE, date(2022, 1, 2))) == 1