Destroy-callbacks not working with PostgreSQL but works fine with sqlite3

Hi. I met a very interesting issue related to destroy-callbacks in apps backed with PostgreSQL database. To check this issue, you can create a new app from scratch using rails new testapp -d postgresql, then create a new model, let’s name it Message rails g model Message content and add callbacks

class Message < ApplicationRecord
    before_destroy -> {
    Rails.logger.debug "before_destroy triggered for message #{id}"
  }
  
  after_destroy -> {
    Rails.logger.debug "after_destroy triggered for message #{id}"
  }
  
  after_destroy_commit -> { 
    Rails.logger.debug "after_destroy_commit triggered for message #{id}"
    broadcast_remove_to "chat_room_#{chat_room.id}_messages"
  }
end

then, when you’ll create several records and try to delete using Message.first.destroy you’ll see no log messages in development.log, like on my screenshot

but … if you do the same using sqlite3 database rails new testapp -d sqlite3 the result will be different

I’ve created an issue, but it was closed, I believe, because of misunderstanding. So, in case if you’ll be able to reproduce this issue, please leave a note here and in GitHub issues

For active record issue, there are template that you can include in the pr to help the maintainer understand about your issue

1 Like

update: I’m not sure what was wrong, but after complete deps upgrade, system gems, project (including testapp) gems, homebrew formulae on my Mac, everything - problem was gone. I’ll reopen a new issue in case if problem happens again after deep research and tests