From 0b1b99fcf55e8a69b6ef6f83e40c0e23af153d92 Mon Sep 17 00:00:00 2001 From: mhuseinov <61513701+mhuseinov@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:38:24 -0800 Subject: [PATCH] exclude records from update if there is no applicant (#1366) --- .../application_applicant_on_submissions.py | 17 ++++++++++++----- ...notice_of_intent_applicant_on_submissions.py | 17 ++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bin/migrate-oats-data/applications/submissions/application_applicant_on_submissions.py b/bin/migrate-oats-data/applications/submissions/application_applicant_on_submissions.py index a420e8cfd1..90efd040c2 100644 --- a/bin/migrate-oats-data/applications/submissions/application_applicant_on_submissions.py +++ b/bin/migrate-oats-data/applications/submissions/application_applicant_on_submissions.py @@ -86,20 +86,27 @@ def _update_records(conn, batch_size, cursor, rows): def _prepare_data(rows): data_list = [] for row in rows: - data_list.append(_map_data(row)) + parsed_data = _map_data(row) + if parsed_data: + data_list.append(parsed_data) return data_list def _map_data(row): applicant = ( - row.get("last_name") if row.get("last_name") else row.get("organization_name") + row.get("last_name") + if row.get("last_name", None) + else row.get("organization_name", None) ) - if applicant and row.get("owner_count_extension"): - applicant = f"{applicant} {row.get('owner_count_extension')}" + if applicant: + if row.get("owner_count_extension"): + applicant = f"{applicant} {row.get('owner_count_extension')}" - return {"applicant": applicant, "submission_uuid": row["submission_uuid"]} + return {"applicant": applicant, "submission_uuid": row["submission_uuid"]} + + return None _update_query = """ diff --git a/bin/migrate-oats-data/noi/notice_of_intent_submissions/notice_of_intent_applicant_on_submissions.py b/bin/migrate-oats-data/noi/notice_of_intent_submissions/notice_of_intent_applicant_on_submissions.py index c1d415f90c..b68d5be81b 100644 --- a/bin/migrate-oats-data/noi/notice_of_intent_submissions/notice_of_intent_applicant_on_submissions.py +++ b/bin/migrate-oats-data/noi/notice_of_intent_submissions/notice_of_intent_applicant_on_submissions.py @@ -86,20 +86,27 @@ def _update_records(conn, batch_size, cursor, rows): def _prepare_data(rows): data_list = [] for row in rows: - data_list.append(_map_data(row)) + parsed_data = _map_data(row) + if parsed_data: + data_list.append(parsed_data) return data_list def _map_data(row): applicant = ( - row.get("last_name") if row.get("last_name") else row.get("organization_name") + row.get("last_name") + if row.get("last_name", None) + else row.get("organization_name", None) ) - if applicant and row.get("owner_count_extension"): - applicant = f"{applicant} {row.get('owner_count_extension')}" + if applicant: + if row.get("owner_count_extension"): + applicant = f"{applicant} {row.get('owner_count_extension')}" - return {"applicant": applicant, "submission_uuid": row["submission_uuid"]} + return {"applicant": applicant, "submission_uuid": row["submission_uuid"]} + + return None _update_query = """