luckyframework/avram

SAVEPOINT can only be used in transaction blocks

開放

#1,119 建立於 2025年9月17日

 (1 則留言) (0 個反應) (0 位負責人)Crystal (67 個分叉)auto 404
help wanted

倉庫指標

星標
 (180 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

When using the table locking my specs are failing with this error. I have this code inside of an operation

it "runs" do
  RunUpdates.run do |op, _val|
    op.valid?.should eq(true)
  end
end
# RunUpdates operation
def run
  AppDatabase.with_lock_on(Thing, mode: :row_exclusive) do
    SaveThing.update!(thing, whatever: true)
  end

  SaveOther.create!(number: 1)
end
       SAVEPOINT can only be used in transaction blocks (PQ::PQError)
         from lib/pg/src/pq/connection.cr:214:7 in 'handle_error'
         from lib/pg/src/pq/connection.cr:197:7 in 'handle_async_frames'
         from lib/pg/src/pq/connection.cr:173:7 in 'read'
         from lib/pg/src/pq/connection.cr:168:7 in 'read'
         from lib/pg/src/pq/connection.cr:446:31 in 'expect_frame'
         from lib/pg/src/pq/connection.cr:445:5 in 'expect_frame'
         from lib/pg/src/pg/result_set.cr:40:15 in 'move_next'
         from lib/db/src/db/result_set.cr:39:13 in 'perform_exec'
         from lib/db/src/db/statement.cr:93:9 in 'perform_exec_and_release'
         from lib/db/src/db/statement.cr:78:7 in 'exec:args'
         from lib/db/src/db/query_methods.cr:275:7 in 'exec'
         from lib/db/src/db/connection.cr:131:7 in 'perform_create_savepoint'
         from lib/avram/src/ext/db/transaction.cr:24:7 in 'initialize'
         from lib/avram/src/ext/db/transaction.cr:21:5 in 'new'
         from lib/db/src/db/transaction.cr:85:7 in 'create_save_point_transaction'
         from lib/db/src/db/transaction.cr:81:7 in 'create_save_point_transaction'
         from lib/db/src/db/transaction.cr:65:7 in 'begin_transaction'
         from lib/db/src/db/begin_transaction.cr:19:12 in 'save'
         from lib/avram/src/avram/save_operation.cr:243:8 in 'save!'

Removing the AppDatabase.with_lock_on block resolves the error. Strange thing is I am using this in another area with no issues... so I'm not sure what's different here 🤔

貢獻者指南