From 2a704dff61bc7832cc7af26f2539c39c3fc4a5a9 Mon Sep 17 00:00:00 2001 From: aditya-balachander Date: Thu, 12 Dec 2024 23:36:56 +0530 Subject: [PATCH] Fix for no records inserted when no records in target and threshold 0 --- cumulusci/tasks/bulkdata/select_utils.py | 2 +- .../tasks/bulkdata/tests/test_select_utils.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cumulusci/tasks/bulkdata/select_utils.py b/cumulusci/tasks/bulkdata/select_utils.py index fedc1398bb..b15389402b 100644 --- a/cumulusci/tasks/bulkdata/select_utils.py +++ b/cumulusci/tasks/bulkdata/select_utils.py @@ -292,7 +292,7 @@ def similarity_post_process( ]: """Processes the query results for the similarity selection strategy""" # Handle case where query returns 0 records - if not query_records and not threshold: + if not query_records and threshold is None: error_message = f"No records found for {sobject} in the target org." return [], [], error_message diff --git a/cumulusci/tasks/bulkdata/tests/test_select_utils.py b/cumulusci/tasks/bulkdata/tests/test_select_utils.py index 6460f18bdc..447cdccef6 100644 --- a/cumulusci/tasks/bulkdata/tests/test_select_utils.py +++ b/cumulusci/tasks/bulkdata/tests/test_select_utils.py @@ -403,6 +403,33 @@ def test_similarity_post_process_with_no_records(): assert error_message == f"No records found for {sobject} in the target org." +def test_similarity_post_process_with_no_records__zero_threshold(): + select_operator = SelectOperationExecutor(SelectStrategy.SIMILARITY) + load_records = [["Aditya", "Salesforce"], ["Jawad", "Salesforce"]] + query_records = [] + num_records = 2 + sobject = "Lead" + ( + selected_records, + insert_records, + error_message, + ) = select_operator.select_post_process( + load_records=load_records, + query_records=query_records, + num_records=num_records, + sobject=sobject, + weights=[1, 1, 1], + fields=["LastName", "Company"], + threshold=0, + ) + + # Assert that it inserts everything + assert selected_records == [None, None] + assert insert_records[0] == ["Aditya", "Salesforce"] + assert insert_records[1] == ["Jawad", "Salesforce"] + assert error_message is None + + def test_calculate_levenshtein_distance_basic(): record1 = ["hello", "world"] record2 = ["hullo", "word"]