From a34b8cd33dfca3886304396e1adcdfb19d606c73 Mon Sep 17 00:00:00 2001 From: Sergei Poljanski Date: Tue, 26 May 2026 18:34:45 +0300 Subject: [PATCH] fix: assign uuid after Invoice.new to avoid mass-assignment restriction Sequel guards primary keys against mass assignment, so passing uuid: to Invoice.new raised MassAssignmentRestriction and turned every invoice creation into a 500. Build the instance with the rest of the fields, then set uuid as an attribute before returning. --- lib/invoice.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/invoice.rb b/lib/invoice.rb index 7354f48..4aebf8b 100644 --- a/lib/invoice.rb +++ b/lib/invoice.rb @@ -49,8 +49,7 @@ class Invoice < Sequel::Model(:invoices) items = normalize_items(params.fetch(:items)) subtotal = items.sum { |i| BigDecimal(i['qty'].to_s) * BigDecimal(i['unit_price'].to_s) } - Invoice.new( - uuid: SecureRandom.uuid, + invoice = Invoice.new( number: allocate_number, client_name: params.fetch(:client_name).to_s.strip, client_email: params.fetch(:client_email).to_s.strip, @@ -65,6 +64,8 @@ class Invoice < Sequel::Model(:invoices) pdf_key: '', created_at: Time.now.utc ) + invoice.uuid = SecureRandom.uuid + invoice end private