<commit_before>class ActiveRecordWithoutCallbacks
  def self.wo_callbacks(klass)
    #List of various possible callbacks.
    takes = [:_create_callbacks, :_find_callbacks, :_initialize_callbacks, :_destroy_callbacks, :_commit_callbacks, :_rollback_callbacks, :_save_callbacks, :_touch_callbacks, :_update_callbacks, :_validate_callbacks, :_validation_callbacks]
    
    #Array containing previous values.
    saved = []
    
    #Thread.exclusive do
      takes.each do |take|
        #Store previous value for restoring later.
        saved << {
          :take => take,
          :value => klass.__send__(take)
        }
        
        #Clear all callbacks.
        klass.__send__("#{take}=", [])
        
        raise "Expected '#{take}' to be empty but it wasnt: #{klass.__send__(take)}" unless klass.__send__(take).empty?
      end
      
      begin
        return yield
      ensure
        #Restore previous callbacks.
        saved.each do |save|
          klass.__send__("#{save[:take]}=", save[:value])
        end
      end
    #end
  end
end<commit_msg>Tried to fix a bug.<commit_after>class ActiveRecordWithoutCallbacks
  TRUE_BLOCK = proc{ true }
  
  def self.wo_callbacks(klass)
    #List of various possible callbacks.
    takes = [:_create_callbacks, :_find_callbacks, :_initialize_callbacks, :_destroy_callbacks, :_commit_callbacks, :_rollback_callbacks, :_save_callbacks, :_touch_callbacks, :_update_callbacks, :_validate_callbacks, :_validation_callbacks, ]
    
    #Array containing previous values.
    saved = []
    
    Thread.exclusive do
      takes.each do |take|
        #Store previous value for restoring later.
        saved << {
          :take => take,
          :value => klass.__send__(take)
        }
        
        #Clear all callbacks.
        klass.__send__("#{take}=", [])
        
        #Test that callbacks really was cleared.
        raise "Expected '#{take}' to be empty but it wasnt: #{klass.__send__(take)}" unless klass.__send__(take).empty?
      end
      
      klass.after_save(&TRUE_BLOCK)
      
      begin
        return yield
      ensure
        #Restore previous callbacks.
        saved.each do |save|
          klass.__send__("#{save[:take]}=", save[:value])
        end
        
        klass.after_save(&TRUE_BLOCK)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10310612597066436, 'fraction_numerical': 0.0, 'mean_word_length': 2.461194029850746, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2123566', 'n_tokens_mistral': 684, 'n_tokens_neox': 701, 'n_words': 166}