bullet-train-pro / bullet_train-action_models

Other
4 stars 1 forks source link

Fix overwrite bug #64

Closed phillipn closed 1 year ago

phillipn commented 1 year ago

Ilya uploaded a huge CSV Friday night. It completed many hours later, but no contacts were created.

We need to add a couple presence checks so that we do not arbitrarily overwrite contacts unrelated to the upload. Below you can see why the added presence checks are necessary

[1][14:31:01](prod)> w = Workspace.find('WvmmMv')
=> #<Workspace id: 42, name: "QA Workspace", created_at: "2021-09-20 18:17:57.468935000 +0000", update...

[2][14:31:24](prod)> i = Contacts::CsvImportAction.find('WjNywe')
=> #<Contacts::CsvImportAction id: 69, workspace_id: 42, target_all: false, target_ids: nil, started_a...

[3][14:31:39](prod)> ap i.send(:find_or_create_by_fields) # THE FIRST ISSUE!!!!
[]
=> nil

[4][14:32:16](prod)> row= i.send(:csv)[1]
=> #<CSV::Row "email_address":"dawne@pagac.net" "first_name":"Lucius" "last_name":"Hirthe">

[5][14:32:37](prod)> find_or_create_by_fields = i.send(:find_or_create_by_fields)
=> []

[6][14:32:56](prod)> where_clause = i.send(:map_row, row).filter { |key, _| find_or_create_by_fields.includ
e?(key) }
=> {}

[7][14:33:06](prod)> subject = i.send(:subject)
=> #<ActiveRecord::Relation [#<Contact id: 203, workspace_id: 42, email_address: "lemuel@quigley.info"...

[8][14:33:19](prod)> subject.find_by(where_clause) # THE SECOND ISSUE!!!! Trying to filter for nothing will return a result all the time
=> #<Contact id: 203, workspace_id: 42, email_address: "lemuel@quigley.info", first_name: "Kaitlin", last_name: "Welch", created_at: "2021-09-20 18:39:01.167209000 +0000", updated_at: "2023-03-26 12:00:09.429525000 +0000", phone_number: nil, time_zone: nil, uuid: "e44231f6089313bf5fdf82f6a2fc4f9b", default_address_id: nil, email_suppression_reason: nil, default_billing_payment_method_id: nil, payment_gateway_revision: nil, unsubscribed_at: nil, last_notification_email_sent_at: nil, anonymous: 0, community_bio: nil, fb_url: nil, twitter_url: nil, instagram_url: nil, linkedin_url: nil, website_url: nil, avatar_image_id: nil, is_community_flagged: nil, limit_chat: nil, transactions_total_amount: 0.0, deleted_at: nil, personal_data_redacted: false>

[10][14:34:00](prod)> subject.klass.find_by(where_clause)
=> #<Contact id: 1, workspace_id: 8, email_address: nil, first_name: nil, last_name: nil, created_at: "2021-08-25 23:35:02.271079000 +0000", updated_at: "2021-08-25 23:35:02.271079000 +0000", phone_number: nil, time_zone: nil, uuid: "5ffa63904f80579cd1e0fb0aebbf8617", default_address_id: nil, email_suppression_reason: nil, default_billing_payment_method_id: nil, payment_gateway_revision: nil, unsubscribed_at: nil, last_notification_email_sent_at: nil, anonymous: 1, community_bio: nil, fb_url: nil, twitter_url: nil, instagram_url: nil, linkedin_url: nil, website_url: nil, avatar_image_id: nil, is_community_flagged: nil, limit_chat: nil, transactions_total_amount: 0.0, deleted_at: nil, personal_data_redacted: false>

[11][14:34:07](prod)> where_clause
=> {}