Merge pull request #18349 from jdelStrother/primarykeyless
Fix rollback of primarykey-less tables
This commit is contained in:
commit
08d6eb2370
@ -378,7 +378,7 @@ def restore_transaction_record_state(force = false) #:nodoc:
|
||||
thaw unless restore_state[:frozen?]
|
||||
@new_record = restore_state[:new_record]
|
||||
@destroyed = restore_state[:destroyed]
|
||||
write_attribute(self.class.primary_key, restore_state[:id])
|
||||
write_attribute(self.class.primary_key, restore_state[:id]) if self.class.primary_key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -650,6 +650,28 @@ def test_transactions_state_from_commit
|
||||
assert transaction.state.committed?
|
||||
end
|
||||
|
||||
def test_transaction_rollback_with_primarykeyless_tables
|
||||
connection = ActiveRecord::Base.connection
|
||||
connection.create_table(:transaction_without_primary_keys, force: true, id: false) do |t|
|
||||
t.integer :thing_id
|
||||
end
|
||||
|
||||
klass = Class.new(ActiveRecord::Base) do
|
||||
self.table_name = 'transaction_without_primary_keys'
|
||||
after_commit { } # necessary to trigger the has_transactional_callbacks branch
|
||||
end
|
||||
|
||||
assert_no_difference(-> { klass.count }) do
|
||||
ActiveRecord::Base.transaction do
|
||||
klass.create!
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
ensure
|
||||
connection.execute("DROP TABLE IF EXISTS transaction_without_primary_keys")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
%w(validation save destroy).each do |filter|
|
||||
|
Loading…
Reference in New Issue
Block a user