From 5f201e77eda4729adf82c84c318bd3895e299a0f Mon Sep 17 00:00:00 2001 From: Paul Bugni Date: Tue, 6 Feb 2024 17:17:23 -0800 Subject: [PATCH] Last few cases improved by eliminating/correcting bogus consents. --- portal/migrations/versions/edb52362d013_.py | 45 ++++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/portal/migrations/versions/edb52362d013_.py b/portal/migrations/versions/edb52362d013_.py index f7f15bbac..6dced10ea 100644 --- a/portal/migrations/versions/edb52362d013_.py +++ b/portal/migrations/versions/edb52362d013_.py @@ -53,14 +53,18 @@ def delete_user_consent(user_id, user_consent_id): def update_user_consent(user_id, user_consent_id, acceptance_date): uc = UserConsent.query.filter( UserConsent.id == user_consent_id).filter( - UserConsent.user_id == user_id).one() - uc.acceptance_date = acceptance_date + UserConsent.user_id == user_id).first() + if uc: + uc.acceptance_date = acceptance_date + return True - bogus_values = [ + bogus_values = ( {'user_id': 101, 'user_consent_id': 219}, {'user_id': 145, 'user_consent_id': 1238}, {'user_id': 164, 'user_consent_id': 218}, {'user_id': 224, 'user_consent_id': 211}, + {'user_id': 310, 'user_consent_id': 1198}, + {'user_id': 310, 'user_consent_id': 1199}, {'user_id': 310, 'user_consent_id': 1200}, {'user_id': 4316, 'user_consent_id': 5033}, {'user_id': 4316, 'user_consent_id': 5032}, @@ -68,27 +72,28 @@ def update_user_consent(user_id, user_consent_id, acceptance_date): {'user_id': 774, 'user_consent_id': 897}, {'user_id': 723, 'user_consent_id': 551}, {'user_id': 653, 'user_consent_id': 820}, - ] + {'user_id': 563, 'user_consent_id': 5896}, + {'user_id': 6686, 'user_consent_id': 6117}, + ) - correct_values = [] - # {'user_id': 719, 'user_consent_id': 544, 'acceptance_date': '2018/05/29 00:00:00'}, - # {'user_id': 723, 'user_consent_id': 551, 'acceptance_date': '2018/05/16 00:00:00'}, - #] + correct_values = ( + {'user_id': 986, 'user_consent_id': 7434, 'acceptance_date': '2023/06/22 18:00:00'}, + ) for row in correct_values: - update_user_consent( - user_id=row['user_id'], - user_consent_id=row['user_consent_id'], - acceptance_date=row['acceptance_date']) - audit_insert( - subject_id=row['user_id'], - user_consent_id=row['user_consent_id'], - acceptance_date=row['acceptance_date']) - session.commit() + if update_user_consent( + user_id=row['user_id'], + user_consent_id=row['user_consent_id'], + acceptance_date=row['acceptance_date']): + audit_insert( + subject_id=row['user_id'], + user_consent_id=row['user_consent_id'], + acceptance_date=row['acceptance_date']) + session.commit() for row in bogus_values: - if delete_user_consent( - user_id=row['user_id'], - user_consent_id=row['user_consent_id']): + if delete_user_consent( + user_id=row['user_id'], + user_consent_id=row['user_consent_id']): audit_insert( subject_id=row['user_id'], user_consent_id=row['user_consent_id'])