From a5f2022d6031549b7e0bed43f88cf323a417f4bc Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 10:02:26 -0700 Subject: [PATCH 01/53] fix inbound_number_dao --- app/dao/inbound_numbers_dao.py | 35 +++++++++++++++++++++------------- app/service_invite/rest.py | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 0a390c024..bb7d32595 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -1,24 +1,30 @@ +from sqlalchemy import select, update + from app import db from app.dao.dao_utils import autocommit from app.models import InboundNumber def dao_get_inbound_numbers(): - return InboundNumber.query.order_by(InboundNumber.updated_at).all() + stmt = select(InboundNumber).order_by(InboundNumber.updated_at) + return db.session.execute(stmt).all() def dao_get_available_inbound_numbers(): - return InboundNumber.query.filter( + stmt = select(InboundNumber).filter( InboundNumber.active, InboundNumber.service_id.is_(None) - ).all() + ) + return db.session.execute(stmt).all() def dao_get_inbound_number_for_service(service_id): - return InboundNumber.query.filter(InboundNumber.service_id == service_id).first() + stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id) + return db.session.execute(stmt).scalars().first() def dao_get_inbound_number(inbound_number_id): - return InboundNumber.query.filter(InboundNumber.id == inbound_number_id).first() + stmt = select(InboundNumber).filter(InboundNumber.id == inbound_number_id) + return db.session.execute(stmt).scalars().first() @autocommit @@ -29,9 +35,8 @@ def dao_set_inbound_number_to_service(service_id, inbound_number): @autocommit def dao_set_inbound_number_active_flag(service_id, active): - inbound_number = InboundNumber.query.filter( - InboundNumber.service_id == service_id - ).first() + stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id) + inbound_number = db.session.execute(stmt).scalars().first() inbound_number.active = active db.session.add(inbound_number) @@ -39,9 +44,13 @@ def dao_set_inbound_number_active_flag(service_id, active): @autocommit def dao_allocate_number_for_service(service_id, inbound_number_id): - updated = InboundNumber.query.filter_by( - id=inbound_number_id, active=True, service_id=None - ).update({"service_id": service_id}) - if not updated: + stmt = ( + update(InboundNumber) + .filter_by(id=inbound_number_id, active=True, service_id=None) + .values({"service_id": service_id}) + ) + result = db.session.execute(stmt) + db.session.commit() + if not result.rowcount == 0: raise Exception("Inbound number: {} is not available".format(inbound_number_id)) - return InboundNumber.query.get(inbound_number_id) + return db.session.get(InboundNumber, inbound_number_id) diff --git a/app/service_invite/rest.py b/app/service_invite/rest.py index f6d9627da..5728b3ed5 100644 --- a/app/service_invite/rest.py +++ b/app/service_invite/rest.py @@ -86,7 +86,7 @@ def _create_service_invite(invited_user, invite_link_host): redis_store.set( f"email-personalisation-{saved_notification.id}", json.dumps(personalisation), - ex=2*24*60*60, + ex=2 * 24 * 60 * 60, ) send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY) From bc235eb2fd639bd55cdd8b269ae3a3d3fd770bbf Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 10:08:35 -0700 Subject: [PATCH 02/53] fix inbound_number_dao --- app/dao/inbound_numbers_dao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index bb7d32595..30eb8fe62 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -7,14 +7,14 @@ def dao_get_inbound_numbers(): stmt = select(InboundNumber).order_by(InboundNumber.updated_at) - return db.session.execute(stmt).all() + return db.session.execute(stmt).scalars().all() def dao_get_available_inbound_numbers(): stmt = select(InboundNumber).filter( InboundNumber.active, InboundNumber.service_id.is_(None) ) - return db.session.execute(stmt).all() + return db.session.execute(stmt).scalars().all() def dao_get_inbound_number_for_service(service_id): From b39d5f5b53d0cbcbfb40132b4ab1126e104f46a9 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 10:42:03 -0700 Subject: [PATCH 03/53] fix inbound_number_dao --- app/dao/inbound_numbers_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 30eb8fe62..ce3d594d2 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -46,7 +46,7 @@ def dao_set_inbound_number_active_flag(service_id, active): def dao_allocate_number_for_service(service_id, inbound_number_id): stmt = ( update(InboundNumber) - .filter_by(id=inbound_number_id, active=True, service_id=None) + .where(id=inbound_number_id, active=True, service_id=None) .values({"service_id": service_id}) ) result = db.session.execute(stmt) From 6dba25a716228e3e5afc45f631b35367f9929004 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 10:59:06 -0700 Subject: [PATCH 04/53] fix inbound_number_dao --- app/dao/inbound_numbers_dao.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index ce3d594d2..315470af3 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -1,4 +1,4 @@ -from sqlalchemy import select, update +from sqlalchemy import and_, select, update from app import db from app.dao.dao_utils import autocommit @@ -46,7 +46,13 @@ def dao_set_inbound_number_active_flag(service_id, active): def dao_allocate_number_for_service(service_id, inbound_number_id): stmt = ( update(InboundNumber) - .where(id=inbound_number_id, active=True, service_id=None) + .where( + and_( + InboundNumber.id == inbound_number_id, + InboundNumber.active is True, + InboundNumber.service_id is None, + ) + ) .values({"service_id": service_id}) ) result = db.session.execute(stmt) From 9a98db12da2efc7679e162c4c2503590488065b9 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 11:09:25 -0700 Subject: [PATCH 05/53] fix inbound_number_dao --- app/dao/inbound_numbers_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 315470af3..49e7fe138 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -7,7 +7,7 @@ def dao_get_inbound_numbers(): stmt = select(InboundNumber).order_by(InboundNumber.updated_at) - return db.session.execute(stmt).scalars().all() + return db.session.execute(stmt).all() def dao_get_available_inbound_numbers(): From 6bc20acba09bb3e517e8695a0c97499b7452c3dc Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 11:24:10 -0700 Subject: [PATCH 06/53] revert and try again --- app/dao/inbound_numbers_dao.py | 35 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 49e7fe138..89ac76e58 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -1,4 +1,4 @@ -from sqlalchemy import and_, select, update +from sqlalchemy import select from app import db from app.dao.dao_utils import autocommit @@ -14,17 +14,15 @@ def dao_get_available_inbound_numbers(): stmt = select(InboundNumber).filter( InboundNumber.active, InboundNumber.service_id.is_(None) ) - return db.session.execute(stmt).scalars().all() + return db.session.execute(stmt).all() def dao_get_inbound_number_for_service(service_id): - stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id) - return db.session.execute(stmt).scalars().first() + return InboundNumber.query.filter(InboundNumber.service_id == service_id).first() def dao_get_inbound_number(inbound_number_id): - stmt = select(InboundNumber).filter(InboundNumber.id == inbound_number_id) - return db.session.execute(stmt).scalars().first() + return InboundNumber.query.filter(InboundNumber.id == inbound_number_id).first() @autocommit @@ -35,8 +33,9 @@ def dao_set_inbound_number_to_service(service_id, inbound_number): @autocommit def dao_set_inbound_number_active_flag(service_id, active): - stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id) - inbound_number = db.session.execute(stmt).scalars().first() + inbound_number = InboundNumber.query.filter( + InboundNumber.service_id == service_id + ).first() inbound_number.active = active db.session.add(inbound_number) @@ -44,19 +43,9 @@ def dao_set_inbound_number_active_flag(service_id, active): @autocommit def dao_allocate_number_for_service(service_id, inbound_number_id): - stmt = ( - update(InboundNumber) - .where( - and_( - InboundNumber.id == inbound_number_id, - InboundNumber.active is True, - InboundNumber.service_id is None, - ) - ) - .values({"service_id": service_id}) - ) - result = db.session.execute(stmt) - db.session.commit() - if not result.rowcount == 0: + updated = InboundNumber.query.filter_by( + id=inbound_number_id, active=True, service_id=None + ).update({"service_id": service_id}) + if not updated: raise Exception("Inbound number: {} is not available".format(inbound_number_id)) - return db.session.get(InboundNumber, inbound_number_id) + return InboundNumber.query.get(inbound_number_id) From ce007a659b22fd62a2dbd4c1762dd53c80ca4716 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 11:40:04 -0700 Subject: [PATCH 07/53] down to line 17 --- app/dao/inbound_numbers_dao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 89ac76e58..554d4bcb7 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -7,14 +7,14 @@ def dao_get_inbound_numbers(): stmt = select(InboundNumber).order_by(InboundNumber.updated_at) - return db.session.execute(stmt).all() + return db.session.execute(stmt).scalars().all() def dao_get_available_inbound_numbers(): stmt = select(InboundNumber).filter( InboundNumber.active, InboundNumber.service_id.is_(None) ) - return db.session.execute(stmt).all() + return db.session.execute(stmt).scalars().all() def dao_get_inbound_number_for_service(service_id): From 0015df31e1d13d8de4f1809473fddc85f3a4f6d4 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 11:48:20 -0700 Subject: [PATCH 08/53] down to line 33 --- app/dao/inbound_numbers_dao.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 554d4bcb7..988d297fb 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -18,11 +18,13 @@ def dao_get_available_inbound_numbers(): def dao_get_inbound_number_for_service(service_id): - return InboundNumber.query.filter(InboundNumber.service_id == service_id).first() + stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id) + return db.session.execute(stmt).scalars().first() def dao_get_inbound_number(inbound_number_id): - return InboundNumber.query.filter(InboundNumber.id == inbound_number_id).first() + stmt = select(InboundNumber).filter(InboundNumber.id == inbound_number_id) + return db.session.execute(stmt).scalars().first() @autocommit From 963acac069a8acade5cf134d57fff9c49a02cecd Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:03:23 -0700 Subject: [PATCH 09/53] down to line 44 --- app/dao/inbound_numbers_dao.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 988d297fb..18d08c999 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -35,9 +35,10 @@ def dao_set_inbound_number_to_service(service_id, inbound_number): @autocommit def dao_set_inbound_number_active_flag(service_id, active): - inbound_number = InboundNumber.query.filter( + stmt = select(InboundNumber).filter( InboundNumber.service_id == service_id - ).first() + ) + inbound_number = db.session.execute(stmt).scalars().first() inbound_number.active = active db.session.add(inbound_number) From bc9ff7405f61764cd966e05497b14c05544bda12 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:13:24 -0700 Subject: [PATCH 10/53] fix update --- app/dao/inbound_numbers_dao.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/dao/inbound_numbers_dao.py b/app/dao/inbound_numbers_dao.py index 18d08c999..a86ba530e 100644 --- a/app/dao/inbound_numbers_dao.py +++ b/app/dao/inbound_numbers_dao.py @@ -1,4 +1,4 @@ -from sqlalchemy import select +from sqlalchemy import and_, select, update from app import db from app.dao.dao_utils import autocommit @@ -35,9 +35,7 @@ def dao_set_inbound_number_to_service(service_id, inbound_number): @autocommit def dao_set_inbound_number_active_flag(service_id, active): - stmt = select(InboundNumber).filter( - InboundNumber.service_id == service_id - ) + stmt = select(InboundNumber).filter(InboundNumber.service_id == service_id) inbound_number = db.session.execute(stmt).scalars().first() inbound_number.active = active @@ -46,9 +44,18 @@ def dao_set_inbound_number_active_flag(service_id, active): @autocommit def dao_allocate_number_for_service(service_id, inbound_number_id): - updated = InboundNumber.query.filter_by( - id=inbound_number_id, active=True, service_id=None - ).update({"service_id": service_id}) - if not updated: + stmt = ( + update(InboundNumber) + .where( + and_( + InboundNumber.id == inbound_number_id, # noqa + InboundNumber.active == True, # noqa + InboundNumber.service_id == None, # noqa + ) + ) + .values({"service_id": service_id}) + ) + result = db.session.execute(stmt) + if result.rowcount == 0: raise Exception("Inbound number: {} is not available".format(inbound_number_id)) - return InboundNumber.query.get(inbound_number_id) + return db.session.get(InboundNumber, inbound_number_id) From c818bac288462952f8a81363fb454f4cbf290cf7 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:24:23 -0700 Subject: [PATCH 11/53] start InboundSmsDao --- app/dao/inbound_sms_dao.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 272ae5e1c..377930099 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -1,7 +1,7 @@ from flask import current_app from sqlalchemy import and_, desc from sqlalchemy.dialects.postgresql import insert -from sqlalchemy.orm import aliased +from sqlalchemy.orm import aliased, select from app import db from app.dao.dao_utils import autocommit @@ -18,8 +18,10 @@ def dao_create_inbound_sms(inbound_sms): def dao_get_inbound_sms_for_service( service_id, user_number=None, *, limit_days=None, limit=None ): - q = InboundSms.query.filter(InboundSms.service_id == service_id).order_by( - InboundSms.created_at.desc() + q = ( + select(InboundSms) + .filter(InboundSms.service_id == service_id) + .order_by(InboundSms.created_at.desc()) ) if limit_days is not None: start_date = midnight_n_days_ago(limit_days) @@ -31,7 +33,7 @@ def dao_get_inbound_sms_for_service( if limit: q = q.limit(limit) - return q.all() + return db.session.execute(q).scalars().all() def dao_get_paginated_inbound_sms_for_service_for_public_api( @@ -58,10 +60,12 @@ def dao_get_paginated_inbound_sms_for_service_for_public_api( def dao_count_inbound_sms_for_service(service_id, limit_days): - return InboundSms.query.filter( + stmt = select(InboundSms).filter( InboundSms.service_id == service_id, InboundSms.created_at >= midnight_n_days_ago(limit_days), - ).count() + ) + result = db.session.execute(stmt) + return result.rowcount def _insert_inbound_sms_history(subquery, query_limit=10000): From 608f1ec3a3d61d5d7aa9602a56fcc671beb98132 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:27:17 -0700 Subject: [PATCH 12/53] start InboundSmsDao --- app/dao/inbound_sms_dao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 377930099..9df236733 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -1,7 +1,7 @@ from flask import current_app -from sqlalchemy import and_, desc +from sqlalchemy import and_, desc, select from sqlalchemy.dialects.postgresql import insert -from sqlalchemy.orm import aliased, select +from sqlalchemy.orm import aliased from app import db from app.dao.dao_utils import autocommit From 672fb364ec6676d441ee88720a9cfb048d0553d2 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:36:26 -0700 Subject: [PATCH 13/53] start InboundSmsDao --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 9df236733..c3fac73ae 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -64,7 +64,7 @@ def dao_count_inbound_sms_for_service(service_id, limit_days): InboundSms.service_id == service_id, InboundSms.created_at >= midnight_n_days_ago(limit_days), ) - result = db.session.execute(stmt) + result = db.session.execute(stmt).all() return result.rowcount From 0f1d70f593f2a006397dd52f5b68e2b4924ce1f1 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:44:28 -0700 Subject: [PATCH 14/53] start InboundSmsDao --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index c3fac73ae..f7c9e2e77 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -64,7 +64,7 @@ def dao_count_inbound_sms_for_service(service_id, limit_days): InboundSms.service_id == service_id, InboundSms.created_at >= midnight_n_days_ago(limit_days), ) - result = db.session.execute(stmt).all() + result = db.session.execute(stmt).scalar() return result.rowcount From af22cbcab96028be07fd9b9a190e6fc6c8abac29 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 12:58:35 -0700 Subject: [PATCH 15/53] start InboundSmsDao --- app/dao/inbound_sms_dao.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index f7c9e2e77..104534bec 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -1,5 +1,5 @@ from flask import current_app -from sqlalchemy import and_, desc, select +from sqlalchemy import and_, desc, func, select from sqlalchemy.dialects.postgresql import insert from sqlalchemy.orm import aliased @@ -60,12 +60,16 @@ def dao_get_paginated_inbound_sms_for_service_for_public_api( def dao_count_inbound_sms_for_service(service_id, limit_days): - stmt = select(InboundSms).filter( - InboundSms.service_id == service_id, - InboundSms.created_at >= midnight_n_days_ago(limit_days), + stmt = ( + select(func.count()) + .select_from(InboundSms) + .filter( + InboundSms.service_id == service_id, + InboundSms.created_at >= midnight_n_days_ago(limit_days), + ) ) result = db.session.execute(stmt).scalar() - return result.rowcount + return result def _insert_inbound_sms_history(subquery, query_limit=10000): From dd4bf2abd35789a4946900f9e6f1b6671ffa9a42 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 13:10:02 -0700 Subject: [PATCH 16/53] fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id --- app/dao/inbound_sms_dao.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 104534bec..e7d0a9dff 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -129,11 +129,13 @@ def delete_inbound_sms_older_than_retention(): "Deleting inbound sms for services with flexible data retention" ) - flexible_data_retention = ( - ServiceDataRetention.query.join(ServiceDataRetention.service) + stmt = ( + select(ServiceDataRetention) + .join(ServiceDataRetention.service) .filter(ServiceDataRetention.notification_type == NotificationType.SMS) .all() ) + flexible_data_retention = db.session.execute(stmt).all() deleted = 0 @@ -166,7 +168,8 @@ def delete_inbound_sms_older_than_retention(): def dao_get_inbound_sms_by_id(service_id, inbound_id): - return InboundSms.query.filter_by(id=inbound_id, service_id=service_id).one() + stmt = select(InboundSms).filter_by(id=inbound_id, service_id=service_id) + return db.session.execute(stmt).scalars().one() def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( From 80d05532e7f0884b884c30230607dbf6056cfb0d Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 13:22:41 -0700 Subject: [PATCH 17/53] fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id --- app/dao/inbound_sms_dao.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index e7d0a9dff..eeec016ce 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -133,7 +133,6 @@ def delete_inbound_sms_older_than_retention(): select(ServiceDataRetention) .join(ServiceDataRetention.service) .filter(ServiceDataRetention.notification_type == NotificationType.SMS) - .all() ) flexible_data_retention = db.session.execute(stmt).all() From cfce20fb464a54b3342324169efee61057dd8a21 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 13:39:05 -0700 Subject: [PATCH 18/53] fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index eeec016ce..de6a78fb6 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -134,7 +134,7 @@ def delete_inbound_sms_older_than_retention(): .join(ServiceDataRetention.service) .filter(ServiceDataRetention.notification_type == NotificationType.SMS) ) - flexible_data_retention = db.session.execute(stmt).all() + flexible_data_retention = db.session.execute(stmt).scalars().all() deleted = 0 From 3c3fb8eb3a8083f06c07e5910778f4051d57d9cd Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 13:52:25 -0700 Subject: [PATCH 19/53] fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id --- app/dao/inbound_sms_dao.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index de6a78fb6..9c76c80a3 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -193,7 +193,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( LIMIT 50 OFFSET :page """ t2 = aliased(InboundSms) - q = ( + stmt = ( db.session.query(InboundSms) .outerjoin( t2, @@ -210,5 +210,18 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( ) .order_by(InboundSms.created_at.desc()) ) - - return q.paginate(page=page, per_page=current_app.config["PAGE_SIZE"]) + offset = (page - 1) * current_app.config["PAGE_SIZE"] + limit = current_app.config["PAGE_SIZE"] + paginated_stmt = stmt.limit(limit).offset(offset) + result = db.session.execute(paginated_stmt).scalars().all() + total_count_stmt = ( + select(func.count()) + .select_from(InboundSms) + .filter( + t2.id == None, # noqa + InboundSms.service_id == service_id, + InboundSms.created_at >= midnight_n_days_ago(limit_days), + ) + ) + total_count = db.session.execute(total_count_stmt).scalar() + return {"items": result, "total_count": total_count} From 6f29a0e5a4e44d3b3872d183a1f269cb975036ab Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 14:05:03 -0700 Subject: [PATCH 20/53] fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id --- app/dao/inbound_sms_dao.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 9c76c80a3..ff6552427 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -194,7 +194,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( """ t2 = aliased(InboundSms) stmt = ( - db.session.query(InboundSms) + select(InboundSms) .outerjoin( t2, and_( @@ -214,6 +214,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( limit = current_app.config["PAGE_SIZE"] paginated_stmt = stmt.limit(limit).offset(offset) result = db.session.execute(paginated_stmt).scalars().all() + print(f"RESULT {result}") total_count_stmt = ( select(func.count()) .select_from(InboundSms) From be56461587082a8784c6d879a70018cea843333c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 14:17:00 -0700 Subject: [PATCH 21/53] fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index ff6552427..330339709 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -213,7 +213,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( offset = (page - 1) * current_app.config["PAGE_SIZE"] limit = current_app.config["PAGE_SIZE"] paginated_stmt = stmt.limit(limit).offset(offset) - result = db.session.execute(paginated_stmt).scalars().all() + result = db.session.execute(paginated_stmt).all() print(f"RESULT {result}") total_count_stmt = ( select(func.count()) From ea32db8df35e01ef8321d2c6c86fb64be653825c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 17 Oct 2024 14:28:22 -0700 Subject: [PATCH 22/53] revert pagination fix --- app/dao/inbound_sms_dao.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 330339709..de6a78fb6 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -193,8 +193,8 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( LIMIT 50 OFFSET :page """ t2 = aliased(InboundSms) - stmt = ( - select(InboundSms) + q = ( + db.session.query(InboundSms) .outerjoin( t2, and_( @@ -210,19 +210,5 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( ) .order_by(InboundSms.created_at.desc()) ) - offset = (page - 1) * current_app.config["PAGE_SIZE"] - limit = current_app.config["PAGE_SIZE"] - paginated_stmt = stmt.limit(limit).offset(offset) - result = db.session.execute(paginated_stmt).all() - print(f"RESULT {result}") - total_count_stmt = ( - select(func.count()) - .select_from(InboundSms) - .filter( - t2.id == None, # noqa - InboundSms.service_id == service_id, - InboundSms.created_at >= midnight_n_days_ago(limit_days), - ) - ) - total_count = db.session.execute(total_count_stmt).scalar() - return {"items": result, "total_count": total_count} + + return q.paginate(page=page, per_page=current_app.config["PAGE_SIZE"]) From fdc494e5610efa19f37610bbb25a24a4a919b601 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 08:12:22 -0700 Subject: [PATCH 23/53] fix delete --- app/dao/inbound_sms_dao.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index de6a78fb6..7721cea2e 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -1,5 +1,5 @@ from flask import current_app -from sqlalchemy import and_, desc, func, select +from sqlalchemy import and_, delete, desc, func, select from sqlalchemy.dialects.postgresql import insert from sqlalchemy.orm import aliased @@ -103,7 +103,7 @@ def _delete_inbound_sms(datetime_to_delete_from, query_filter): query_limit = 10000 subquery = ( - db.session.query(InboundSms.id) + select(InboundSms.id) .filter(InboundSms.created_at < datetime_to_delete_from, *query_filter) .limit(query_limit) .subquery() @@ -115,9 +115,9 @@ def _delete_inbound_sms(datetime_to_delete_from, query_filter): while number_deleted > 0: _insert_inbound_sms_history(subquery, query_limit=query_limit) - number_deleted = InboundSms.query.filter(InboundSms.id.in_(subquery)).delete( - synchronize_session="fetch" - ) + stmt = delete(InboundSms).filter(InboundSms.id.in_(subquery)) + number_deleted = db.session.execute(stmt).rowcount + db.session.commit() deleted += number_deleted return deleted From 78aab59d1589ff890a05cf02bcce5b967177c434 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 08:45:31 -0700 Subject: [PATCH 24/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 7721cea2e..6f25816ca 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -52,11 +52,17 @@ def dao_get_paginated_inbound_sms_for_service_for_public_api( ) filters.append(InboundSms.created_at < older_than_created_at) - query = InboundSms.query.filter(*filters) - - return ( - query.order_by(desc(InboundSms.created_at)).paginate(per_page=page_size).items + # As part of the move to sqlalchemy 2.0, we do this manual pagination + # 1.4 had a paginate() method which assumed 'page' was 1 if it was not specified, + # so we set page to 1 here to mimic that. + page = 1 + query = db.session.query(InboundSms).filter(*filters) + paginated_items = ( + query.order_by(desc(InboundSms.created_at)) + .offset((page - 1) * page_size) + .limit(page_size) ) + return paginated_items def dao_count_inbound_sms_for_service(service_id, limit_days): From 3b651a2716b3dfd003946caa539033a04e7fc8e0 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 09:05:03 -0700 Subject: [PATCH 25/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 6f25816ca..35f4e4bba 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -48,20 +48,13 @@ def dao_get_paginated_inbound_sms_for_service_for_public_api( older_than_created_at = ( db.session.query(InboundSms.created_at) .filter(InboundSms.id == older_than) - .as_scalar() + .scalar_subquery() ) filters.append(InboundSms.created_at < older_than_created_at) # As part of the move to sqlalchemy 2.0, we do this manual pagination - # 1.4 had a paginate() method which assumed 'page' was 1 if it was not specified, - # so we set page to 1 here to mimic that. - page = 1 query = db.session.query(InboundSms).filter(*filters) - paginated_items = ( - query.order_by(desc(InboundSms.created_at)) - .offset((page - 1) * page_size) - .limit(page_size) - ) + paginated_items = query.order_by(desc(InboundSms.created_at)).limit(page_size).all() return paginated_items From c36a1ba221c06e3fdaeaaeebec11ab2411a0dded Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 09:21:04 -0700 Subject: [PATCH 26/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 35f4e4bba..aa74949dc 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -73,7 +73,7 @@ def dao_count_inbound_sms_for_service(service_id, limit_days): def _insert_inbound_sms_history(subquery, query_limit=10000): offset = 0 - inbound_sms_query = db.session.query( + inbound_sms_query = select( InboundSms.id, InboundSms.created_at, InboundSms.service_id, @@ -81,8 +81,10 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): InboundSms.provider_date, InboundSms.provider_reference, InboundSms.provider, - ).filter(InboundSms.id.in_(subquery)) - inbound_sms_count = inbound_sms_query.count() + ).where(InboundSms.id.in_(subquery)) + inbound_sms_count = db.session.execute( + select([db.func.count()]).select_from(inbound_sms_query.subquery()).scalar_one() + ) while offset < inbound_sms_count: statement = insert(InboundSmsHistory).from_select( @@ -93,7 +95,8 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): statement = statement.on_conflict_do_nothing( constraint="inbound_sms_history_pkey" ) - db.session.connection().execute(statement) + db.session.execute(statement) + db.session.commit() offset += query_limit From f207b65c9ac80049935f0f7d5be54b1be1ba8474 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 09:31:12 -0700 Subject: [PATCH 27/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index aa74949dc..1fa89d402 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -73,6 +73,7 @@ def dao_count_inbound_sms_for_service(service_id, limit_days): def _insert_inbound_sms_history(subquery, query_limit=10000): offset = 0 + subquery_select = select(subquery) inbound_sms_query = select( InboundSms.id, InboundSms.created_at, @@ -81,7 +82,8 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): InboundSms.provider_date, InboundSms.provider_reference, InboundSms.provider, - ).where(InboundSms.id.in_(subquery)) + ).where(InboundSms.id.in_(subquery_select)) + inbound_sms_count = db.session.execute( select([db.func.count()]).select_from(inbound_sms_query.subquery()).scalar_one() ) From 001c16bdcea3a0d414cea38bc1cbb8ae913283b7 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 09:40:37 -0700 Subject: [PATCH 28/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 1fa89d402..b0d3c8cb7 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -85,7 +85,7 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): ).where(InboundSms.id.in_(subquery_select)) inbound_sms_count = db.session.execute( - select([db.func.count()]).select_from(inbound_sms_query.subquery()).scalar_one() + select([func.count()]).select_from(inbound_sms_query.subquery()).scalar_one() ) while offset < inbound_sms_count: From cf3e99c80114cd63a9286c28de573553b4d98cee Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 09:50:06 -0700 Subject: [PATCH 29/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index b0d3c8cb7..b143c807e 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -85,7 +85,7 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): ).where(InboundSms.id.in_(subquery_select)) inbound_sms_count = db.session.execute( - select([func.count()]).select_from(inbound_sms_query.subquery()).scalar_one() + select(func.count()).select_from(inbound_sms_query.subquery()).scalar_one() ) while offset < inbound_sms_count: From 5716c86e8a7c27ecc5d426b38c0e5a05d59cd6c4 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 10:03:46 -0700 Subject: [PATCH 30/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index b143c807e..59fe48735 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -85,7 +85,7 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): ).where(InboundSms.id.in_(subquery_select)) inbound_sms_count = db.session.execute( - select(func.count()).select_from(inbound_sms_query.subquery()).scalar_one() + select(func.count()).select_from(inbound_sms_query.subquery()).scalar() or 0 ) while offset < inbound_sms_count: From fed5a842e07fa3efe8eeb86e29892f220ce6b7b4 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 10:16:09 -0700 Subject: [PATCH 31/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 59fe48735..8925b9b72 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -85,7 +85,7 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): ).where(InboundSms.id.in_(subquery_select)) inbound_sms_count = db.session.execute( - select(func.count()).select_from(inbound_sms_query.subquery()).scalar() or 0 + select(func.count()).select_from(inbound_sms_query.subquery()).scalar_one_or_none() or 0 ) while offset < inbound_sms_count: From f12f6b9b63ffc2c1809ca3acaaf551f1430161cb Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 10:27:29 -0700 Subject: [PATCH 32/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 8925b9b72..690b007bc 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -85,7 +85,7 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): ).where(InboundSms.id.in_(subquery_select)) inbound_sms_count = db.session.execute( - select(func.count()).select_from(inbound_sms_query.subquery()).scalar_one_or_none() or 0 + select(func.count()).select_from(inbound_sms_query.subquery()).scalars().one_or_none() or 0 ) while offset < inbound_sms_count: From 697ea84d329c1882c24a758063a547635859f504 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 10:44:56 -0700 Subject: [PATCH 33/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 690b007bc..6d1c266cb 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -84,9 +84,9 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): InboundSms.provider, ).where(InboundSms.id.in_(subquery_select)) - inbound_sms_count = db.session.execute( - select(func.count()).select_from(inbound_sms_query.subquery()).scalars().one_or_none() or 0 - ) + count_query = select(func.count()).select_from(inbound_sms_query.subquery()).scalar() + print(f"COUNT QUERY {count_query}") + inbound_sms_count = db.session.execute(count_query) or 0 while offset < inbound_sms_count: statement = insert(InboundSmsHistory).from_select( From c859c5c53aaf6f5ea16d32763534c2e6f6158f84 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 11:03:21 -0700 Subject: [PATCH 34/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 6d1c266cb..c7c973ea0 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -84,9 +84,8 @@ def _insert_inbound_sms_history(subquery, query_limit=10000): InboundSms.provider, ).where(InboundSms.id.in_(subquery_select)) - count_query = select(func.count()).select_from(inbound_sms_query.subquery()).scalar() - print(f"COUNT QUERY {count_query}") - inbound_sms_count = db.session.execute(count_query) or 0 + count_query = select(func.count()).select_from(inbound_sms_query.subquery()) + inbound_sms_count = db.session.execute(count_query).scalar() or 0 while offset < inbound_sms_count: statement = insert(InboundSmsHistory).from_select( From 73dbca16e115dfa009bcd4aa817c65afd0bdeea1 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 11:18:29 -0700 Subject: [PATCH 35/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index c7c973ea0..93bf02877 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -197,7 +197,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( """ t2 = aliased(InboundSms) q = ( - db.session.query(InboundSms) + select(InboundSms) .outerjoin( t2, and_( @@ -206,12 +206,15 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( InboundSms.created_at < t2.created_at, ), ) - .filter( - t2.id == None, # noqa + .where( + t2.id.is_(None), # noqa InboundSms.service_id == service_id, InboundSms.created_at >= midnight_n_days_ago(limit_days), ) .order_by(InboundSms.created_at.desc()) ) - - return q.paginate(page=page, per_page=current_app.config["PAGE_SIZE"]) + result = db.session.execute(q).scalars().all() + page_size = current_app.config["PAGE_SIZE"] + offset = (page - 1) * page_size + paginated_results = result[offset : offset + page_size] + return paginated_results From 5e8efacdb8c8b5f3cb0c837cd60e5910e6a94974 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 11:33:59 -0700 Subject: [PATCH 36/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 93bf02877..c9b4417e3 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -217,4 +217,23 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( page_size = current_app.config["PAGE_SIZE"] offset = (page - 1) * page_size paginated_results = result[offset : offset + page_size] - return paginated_results + pagination = Pagination(paginated_results, page, page_size, len(result)) + return pagination + + +# TODO remove this when billing dao PR is merged. +class Pagination: + def __init__(self, items, page, per_page, total): + self.items = items + self.page = page + self.per_page = per_page + self.total = total + self.pages = (total + per_page - 1) // per_page + self.prev_num = page - 1 if page > 1 else None + self.next_num = page + 1 if page < self.pages else None + + def has_next(self): + return self.page < self.pages + + def has_prev(self): + return self.page > 1 From a3b2b1940644ed05b375bcb94748c8a47fef596a Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 11:55:30 -0700 Subject: [PATCH 37/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index c9b4417e3..75c7515a5 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -1,4 +1,4 @@ -from flask import current_app +from flask import current_app, json from sqlalchemy import and_, delete, desc, func, select from sqlalchemy.dialects.postgresql import insert from sqlalchemy.orm import aliased @@ -217,6 +217,11 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( page_size = current_app.config["PAGE_SIZE"] offset = (page - 1) * page_size paginated_results = result[offset : offset + page_size] + try: + json.dumps(paginated_results) + except TypeError as e: + current_app.logger.exception("Serialization Error") + raise e pagination = Pagination(paginated_results, page, page_size, len(result)) return pagination From 2b1e83cef661fa162ddadf7b0e28a3944b107704 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 12:12:20 -0700 Subject: [PATCH 38/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index 75c7515a5..c45ec2101 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -217,12 +217,15 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( page_size = current_app.config["PAGE_SIZE"] offset = (page - 1) * page_size paginated_results = result[offset : offset + page_size] + serialized_results = [] + for item in paginated_results: + serialized_results.append(item.serialize()) try: - json.dumps(paginated_results) + json.dumps(serialized_results) except TypeError as e: current_app.logger.exception("Serialization Error") raise e - pagination = Pagination(paginated_results, page, page_size, len(result)) + pagination = Pagination(serialized_results, page, page_size, len(result)) return pagination From 567a16fb5387b0a77ecc93403207f70350361969 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 12:23:51 -0700 Subject: [PATCH 39/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 10 +--------- app/inbound_sms/rest.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index c45ec2101..e1e517513 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -217,15 +217,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( page_size = current_app.config["PAGE_SIZE"] offset = (page - 1) * page_size paginated_results = result[offset : offset + page_size] - serialized_results = [] - for item in paginated_results: - serialized_results.append(item.serialize()) - try: - json.dumps(serialized_results) - except TypeError as e: - current_app.logger.exception("Serialization Error") - raise e - pagination = Pagination(serialized_results, page, page_size, len(result)) + pagination = Pagination(paginated_results, page, page_size, len(result)) return pagination diff --git a/app/inbound_sms/rest.py b/app/inbound_sms/rest.py index 7f8742a16..94e508e07 100644 --- a/app/inbound_sms/rest.py +++ b/app/inbound_sms/rest.py @@ -60,9 +60,14 @@ def get_most_recent_inbound_sms_for_service(service_id): results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( service_id, int(page), limit_days ) - return jsonify( - data=[row.serialize() for row in results.items], has_next=results.has_next - ) + print(f"RESULTS {results}") + try: + x = jsonify( + data=[row.serialize() for row in results.items], has_next=results.has_next + ) + except Exception as e: + raise e + return x @inbound_sms.route("/summary") From 9b965ae6bfd50fd54ac757633fe71d2e2ae8bc66 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 12:40:14 -0700 Subject: [PATCH 40/53] fix first paginate method --- app/dao/inbound_sms_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/inbound_sms_dao.py b/app/dao/inbound_sms_dao.py index e1e517513..c9b4417e3 100644 --- a/app/dao/inbound_sms_dao.py +++ b/app/dao/inbound_sms_dao.py @@ -1,4 +1,4 @@ -from flask import current_app, json +from flask import current_app from sqlalchemy import and_, delete, desc, func, select from sqlalchemy.dialects.postgresql import insert from sqlalchemy.orm import aliased From 8d80b2bfff51b4f8c055e6fdcbd1de59046b2204 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 12:52:24 -0700 Subject: [PATCH 41/53] fix first paginate method --- app/inbound_sms/rest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/inbound_sms/rest.py b/app/inbound_sms/rest.py index 94e508e07..4ee6ee1d3 100644 --- a/app/inbound_sms/rest.py +++ b/app/inbound_sms/rest.py @@ -60,10 +60,11 @@ def get_most_recent_inbound_sms_for_service(service_id): results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( service_id, int(page), limit_days ) - print(f"RESULTS {results}") + print(f"RESULTS ITEMS {results.items}") + print(f"RESULTS HAS_NEXT {results.has_next}") try: x = jsonify( - data=[row.serialize() for row in results.items], has_next=results.has_next + data=[row.serialize() for row in results.items], has_next=results.has_next() ) except Exception as e: raise e From d8375ecc94239c6ee982f6bd5ff9024e4fe51b4b Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 13:04:48 -0700 Subject: [PATCH 42/53] fix first paginate method --- tests/app/dao/test_inbound_sms_dao.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/app/dao/test_inbound_sms_dao.py b/tests/app/dao/test_inbound_sms_dao.py index 9f3d6738d..ff8bff0dc 100644 --- a/tests/app/dao/test_inbound_sms_dao.py +++ b/tests/app/dao/test_inbound_sms_dao.py @@ -391,7 +391,7 @@ def test_most_recent_inbound_sms_only_returns_most_recent_for_each_number( ) # noqa assert len(res.items) == 2 - assert res.has_next is False + assert res.has_next() is False assert res.per_page == 3 assert res.items[0].content == "111 5" assert res.items[1].content == "222 2" @@ -454,7 +454,7 @@ def test_most_recent_inbound_sms_paginates_properly(notify_api, sample_service): sample_service.id, limit_days=7, page=1 ) # noqa assert len(res.items) == 2 - assert res.has_next is True + assert res.has_next() is True assert res.per_page == 2 assert res.items[0].content == "444 2" assert res.items[1].content == "333 2" @@ -464,7 +464,7 @@ def test_most_recent_inbound_sms_paginates_properly(notify_api, sample_service): sample_service.id, limit_days=7, page=2 ) # noqa assert len(res.items) == 2 - assert res.has_next is False + assert res.has_next() is False assert res.items[0].content == "222 2" assert res.items[1].content == "111 2" From cf07818d636d056a41a1e626d7e2c3861fc86cb3 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 18 Oct 2024 14:31:40 -0700 Subject: [PATCH 43/53] fix complaint_dao --- app/dao/complaint_dao.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/dao/complaint_dao.py b/app/dao/complaint_dao.py index 1cc12bdae..dd6abc0b8 100644 --- a/app/dao/complaint_dao.py +++ b/app/dao/complaint_dao.py @@ -1,7 +1,7 @@ from datetime import timedelta from flask import current_app -from sqlalchemy import desc +from sqlalchemy import desc, func, select from app import db from app.dao.dao_utils import autocommit @@ -21,17 +21,21 @@ def fetch_paginated_complaints(page=1): def fetch_complaints_by_service(service_id): - return ( - Complaint.query.filter_by(service_id=service_id) + stmt = ( + select(Complaint) + .filter_by(service_id=service_id) .order_by(desc(Complaint.created_at)) - .all() ) + return db.session.execute(stmt).scalars().all() def fetch_count_of_complaints(start_date, end_date): start_date = get_midnight_in_utc(start_date) end_date = get_midnight_in_utc(end_date + timedelta(days=1)) - return Complaint.query.filter( - Complaint.created_at >= start_date, Complaint.created_at < end_date - ).count() + stmt = ( + select(func.count()) + .select_from(Complaint) + .filter(Complaint.created_at >= start_date, Complaint.created_at < end_date) + ) + return db.session.execute(stmt).scalar() or 0 From f633230c5574f660342ba34dcf0f549a81b20abc Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 07:18:52 -0700 Subject: [PATCH 44/53] fix pagination --- app/dao/complaint_dao.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/dao/complaint_dao.py b/app/dao/complaint_dao.py index dd6abc0b8..1682a534a 100644 --- a/app/dao/complaint_dao.py +++ b/app/dao/complaint_dao.py @@ -5,6 +5,7 @@ from app import db from app.dao.dao_utils import autocommit +from app.dao.inbound_sms_dao import Pagination from app.models import Complaint from app.utils import get_midnight_in_utc @@ -15,9 +16,16 @@ def save_complaint(complaint): def fetch_paginated_complaints(page=1): - return Complaint.query.order_by(desc(Complaint.created_at)).paginate( - page=page, per_page=current_app.config["PAGE_SIZE"] - ) + # return Complaint.query.order_by(desc(Complaint.created_at)).paginate( + # page=page, per_page=current_app.config["PAGE_SIZE"] + # ) + page_size = current_app.config["PAGE_SIZE"] + total_count = db.session.scalar(select(func.count()).select_from(Complaint)) + offset = (page - 1) * page_size + stmt = select(Complaint).order_by().offset(offset).limit(page_size) + result = db.session.execute(stmt).scalars() + pagination = Pagination(result, page=page, per_page=page_size, total=total_count) + return pagination def fetch_complaints_by_service(service_id): From 5e3e37377fd0ff194e5d637953aea2f167ddc015 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 07:37:12 -0700 Subject: [PATCH 45/53] fix complaint_dao --- app/dao/complaint_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/complaint_dao.py b/app/dao/complaint_dao.py index 1682a534a..1b53670af 100644 --- a/app/dao/complaint_dao.py +++ b/app/dao/complaint_dao.py @@ -23,7 +23,7 @@ def fetch_paginated_complaints(page=1): total_count = db.session.scalar(select(func.count()).select_from(Complaint)) offset = (page - 1) * page_size stmt = select(Complaint).order_by().offset(offset).limit(page_size) - result = db.session.execute(stmt).scalars() + result = db.session.execute(stmt).scalars().all() pagination = Pagination(result, page=page, per_page=page_size, total=total_count) return pagination From 3d7ab715553028fd476f6271b870697bcce24265 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 07:45:03 -0700 Subject: [PATCH 46/53] fix complaint_dao --- app/dao/complaint_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dao/complaint_dao.py b/app/dao/complaint_dao.py index 1b53670af..2da93b681 100644 --- a/app/dao/complaint_dao.py +++ b/app/dao/complaint_dao.py @@ -22,7 +22,7 @@ def fetch_paginated_complaints(page=1): page_size = current_app.config["PAGE_SIZE"] total_count = db.session.scalar(select(func.count()).select_from(Complaint)) offset = (page - 1) * page_size - stmt = select(Complaint).order_by().offset(offset).limit(page_size) + stmt = select(Complaint).order_by(desc(Complaint.created_at)).offset(offset).limit(page_size) result = db.session.execute(stmt).scalars().all() pagination = Pagination(result, page=page, per_page=page_size, total=total_count) return pagination From 38a2a87a15bd8cb6dcf70baba1a6fca469298545 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 08:01:57 -0700 Subject: [PATCH 47/53] fix test code --- app/dao/complaint_dao.py | 10 ++++++---- tests/app/dao/test_inbound_numbers_dao.py | 5 ++++- tests/app/dao/test_inbound_sms_dao.py | 10 +++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/dao/complaint_dao.py b/app/dao/complaint_dao.py index 2da93b681..63b7487fb 100644 --- a/app/dao/complaint_dao.py +++ b/app/dao/complaint_dao.py @@ -16,13 +16,15 @@ def save_complaint(complaint): def fetch_paginated_complaints(page=1): - # return Complaint.query.order_by(desc(Complaint.created_at)).paginate( - # page=page, per_page=current_app.config["PAGE_SIZE"] - # ) page_size = current_app.config["PAGE_SIZE"] total_count = db.session.scalar(select(func.count()).select_from(Complaint)) offset = (page - 1) * page_size - stmt = select(Complaint).order_by(desc(Complaint.created_at)).offset(offset).limit(page_size) + stmt = ( + select(Complaint) + .order_by(desc(Complaint.created_at)) + .offset(offset) + .limit(page_size) + ) result = db.session.execute(stmt).scalars().all() pagination = Pagination(result, page=page, per_page=page_size, total=total_count) return pagination diff --git a/tests/app/dao/test_inbound_numbers_dao.py b/tests/app/dao/test_inbound_numbers_dao.py index ce3fd6245..ade1f7f94 100644 --- a/tests/app/dao/test_inbound_numbers_dao.py +++ b/tests/app/dao/test_inbound_numbers_dao.py @@ -1,6 +1,8 @@ import pytest +from sqlalchemy import select from sqlalchemy.exc import IntegrityError +from app import db from app.dao.inbound_numbers_dao import ( dao_allocate_number_for_service, dao_get_available_inbound_numbers, @@ -35,7 +37,8 @@ def test_set_service_id_on_inbound_number(notify_db_session, sample_inbound_numb dao_set_inbound_number_to_service(service.id, numbers[0]) - res = InboundNumber.query.filter(InboundNumber.service_id == service.id).all() + stmt = select(InboundNumber).filter(InboundNumber.service_id == service.id) + res = db.session.execute(stmt).all() assert len(res) == 1 assert res[0].service_id == service.id diff --git a/tests/app/dao/test_inbound_sms_dao.py b/tests/app/dao/test_inbound_sms_dao.py index ff8bff0dc..3bc590123 100644 --- a/tests/app/dao/test_inbound_sms_dao.py +++ b/tests/app/dao/test_inbound_sms_dao.py @@ -2,6 +2,7 @@ from itertools import product from freezegun import freeze_time +from sqlalchemy import select from app import db from app.dao.inbound_sms_dao import ( @@ -141,7 +142,8 @@ def test_should_delete_inbound_sms_according_to_data_retention(notify_db_session deleted_count = delete_inbound_sms_older_than_retention() - history = InboundSmsHistory.query.all() + stmt = select(InboundSmsHistory) + history = db.session.execute(stmt).all() assert len(history) == 7 # four deleted for the 3-day service, two for the default seven days one, one for the 30 day @@ -171,7 +173,8 @@ def test_insert_into_inbound_sms_history_when_deleting_inbound_sms(sample_servic create_inbound_sms(sample_service, created_at=datetime(2019, 12, 19, 20, 19)) delete_inbound_sms_older_than_retention() - history = InboundSmsHistory.query.all() + stmt = select(InboundSmsHistory) + history = db.session.execute(stmt).all() assert len(history) == 1 for key_name in [ @@ -226,7 +229,8 @@ def test_delete_inbound_sms_older_than_retention_does_nothing_when_database_conf delete_inbound_sms_older_than_retention() - history = InboundSmsHistory.query.all() + stmt = select(InboundSmsHistory) + history = db.session.execute(stmt).all() assert len(history) == 1 assert history[0].id == inbound_sms_id From a3a5abc521f351985181ac987af6820a21d751ae Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 08:15:07 -0700 Subject: [PATCH 48/53] fix test code --- tests/app/dao/test_inbound_sms_dao.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/app/dao/test_inbound_sms_dao.py b/tests/app/dao/test_inbound_sms_dao.py index 3bc590123..39cdb2f53 100644 --- a/tests/app/dao/test_inbound_sms_dao.py +++ b/tests/app/dao/test_inbound_sms_dao.py @@ -143,7 +143,7 @@ def test_should_delete_inbound_sms_according_to_data_retention(notify_db_session deleted_count = delete_inbound_sms_older_than_retention() stmt = select(InboundSmsHistory) - history = db.session.execute(stmt).all() + history = db.session.execute(stmt).scalars().all() assert len(history) == 7 # four deleted for the 3-day service, two for the default seven days one, one for the 30 day @@ -174,7 +174,7 @@ def test_insert_into_inbound_sms_history_when_deleting_inbound_sms(sample_servic delete_inbound_sms_older_than_retention() stmt = select(InboundSmsHistory) - history = db.session.execute(stmt).all() + history = db.session.execute(stmt).scalars().all() assert len(history) == 1 for key_name in [ @@ -230,7 +230,7 @@ def test_delete_inbound_sms_older_than_retention_does_nothing_when_database_conf delete_inbound_sms_older_than_retention() stmt = select(InboundSmsHistory) - history = db.session.execute(stmt).all() + history = db.session.execute(stmt).scalars().all() assert len(history) == 1 assert history[0].id == inbound_sms_id From 83251ba845ffb2d801571c934e2087cd89374266 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 08:24:23 -0700 Subject: [PATCH 49/53] fix test code --- tests/app/dao/test_inbound_numbers_dao.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app/dao/test_inbound_numbers_dao.py b/tests/app/dao/test_inbound_numbers_dao.py index ade1f7f94..efb1e376c 100644 --- a/tests/app/dao/test_inbound_numbers_dao.py +++ b/tests/app/dao/test_inbound_numbers_dao.py @@ -38,7 +38,7 @@ def test_set_service_id_on_inbound_number(notify_db_session, sample_inbound_numb dao_set_inbound_number_to_service(service.id, numbers[0]) stmt = select(InboundNumber).filter(InboundNumber.service_id == service.id) - res = db.session.execute(stmt).all() + res = db.session.execute(stmt).scalars().all() assert len(res) == 1 assert res[0].service_id == service.id From 2a05cb26aa74be46a09efea255c5d9a7b06bef3e Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 24 Oct 2024 07:14:50 -0700 Subject: [PATCH 50/53] code review feedback --- app/inbound_sms/rest.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/inbound_sms/rest.py b/app/inbound_sms/rest.py index 4ee6ee1d3..1cae7a85b 100644 --- a/app/inbound_sms/rest.py +++ b/app/inbound_sms/rest.py @@ -60,8 +60,6 @@ def get_most_recent_inbound_sms_for_service(service_id): results = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service( service_id, int(page), limit_days ) - print(f"RESULTS ITEMS {results.items}") - print(f"RESULTS HAS_NEXT {results.has_next}") try: x = jsonify( data=[row.serialize() for row in results.items], has_next=results.has_next() From 61cf576faf977a48167faf1364a485e6f03fa483 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 28 Oct 2024 14:01:06 -0700 Subject: [PATCH 51/53] hmmm --- tests/app/dao/test_fact_notification_status_dao.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index 586c1c3ec..304591de3 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -81,25 +81,26 @@ def test_fetch_notification_status_for_service_by_month(notify_db_session): ) assert len(results) == 4 + print(results) assert results[0].month.date() == date(2018, 1, 1) - assert results[0].notification_type == NotificationType.EMAIL + # assert results[0].notification_type == NotificationType.EMAIL # TODO fix/investigate # assert results[0].notification_status == NotificationStatus.DELIVERED assert results[0].count == 1 assert results[1].month.date() == date(2018, 1, 1) - assert results[1].notification_type == NotificationType.SMS + # assert results[1].notification_type == NotificationType.SMS assert results[1].notification_status == NotificationStatus.CREATED assert results[1].count == 1 assert results[2].month.date() == date(2018, 1, 1) - assert results[2].notification_type == NotificationType.SMS + # assert results[2].notification_type == NotificationType.SMS assert results[2].notification_status == NotificationStatus.DELIVERED assert results[2].count == 14 assert results[3].month.date() == date(2018, 2, 1) - assert results[3].notification_type == NotificationType.SMS + # assert results[3].notification_type == NotificationType.SMS assert results[3].notification_status == NotificationStatus.DELIVERED assert results[3].count == 1 From 4d276ad4fe48a0c34e570294fb7805b1e19ead30 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 28 Oct 2024 14:20:54 -0700 Subject: [PATCH 52/53] hmmm --- tests/app/dao/test_fact_notification_status_dao.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index 304591de3..0801142bf 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -84,23 +84,22 @@ def test_fetch_notification_status_for_service_by_month(notify_db_session): print(results) assert results[0].month.date() == date(2018, 1, 1) - # assert results[0].notification_type == NotificationType.EMAIL - # TODO fix/investigate - # assert results[0].notification_status == NotificationStatus.DELIVERED + assert results[0].notification_type == NotificationType.EMAIL + assert results[0].notification_status == NotificationStatus.DELIVERED assert results[0].count == 1 assert results[1].month.date() == date(2018, 1, 1) - # assert results[1].notification_type == NotificationType.SMS + assert results[1].notification_type == NotificationType.SMS assert results[1].notification_status == NotificationStatus.CREATED assert results[1].count == 1 assert results[2].month.date() == date(2018, 1, 1) - # assert results[2].notification_type == NotificationType.SMS + assert results[2].notification_type == NotificationType.SMS assert results[2].notification_status == NotificationStatus.DELIVERED assert results[2].count == 14 assert results[3].month.date() == date(2018, 2, 1) - # assert results[3].notification_type == NotificationType.SMS + assert results[3].notification_type == NotificationType.SMS assert results[3].notification_status == NotificationStatus.DELIVERED assert results[3].count == 1 From 57df2f6d9650c55502be3a977c64573fa4a2115a Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 29 Oct 2024 14:29:25 -0700 Subject: [PATCH 53/53] code review feedback --- tests/app/dao/test_fact_notification_status_dao.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index 0801142bf..ccb0c5a06 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -81,7 +81,6 @@ def test_fetch_notification_status_for_service_by_month(notify_db_session): ) assert len(results) == 4 - print(results) assert results[0].month.date() == date(2018, 1, 1) assert results[0].notification_type == NotificationType.EMAIL