Skip to content

Commit

Permalink
fix: add primary key validation for extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
afthabvp committed Apr 8, 2024
1 parent 4948b80 commit d89d89a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/lib/reverse_etl/extractors/incremental_delta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def process_record(message, sync_run, model)
fingerprint = generate_fingerprint(record.data)
primary_key = record.data.with_indifferent_access[model.primary_key]

return if primary_key.blank?

sync_record = find_or_initialize_sync_record(sync_run, primary_key)
update_or_create_sync_record(sync_record, record, sync_run, fingerprint)
rescue StandardError => e
Expand Down
14 changes: 14 additions & 0 deletions server/spec/lib/reverse_etl/extractors/incremental_delta_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,18 @@

# TODO: test for partial recovery via currrent offset
end

describe "#process_record" do
let(:sync_run) do
create(:sync_run, sync:, workspace: sync.workspace, source:, destination:, model: sync.model, status: "started")
end
let(:model) { create(:model) }

context "when the primary key is blank" do
it "does not create or update sync record" do
message = double("Message", record: double("Record", data: { "id" => nil }))
expect { subject.send(:process_record, message, sync_run, model) }.not_to(change { SyncRecord.count })
end
end
end
end

0 comments on commit d89d89a

Please sign in to comment.