Skip to main content

Redmine save_revision error by DB charset

* Check unit
rails runner "Repository.fetch_changesets" -e production

* ErrorLog

/usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `_query': Mysql2::Error: Incorrect string value:.......) (ActiveRecord::StatementInvalid)

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:80:in `block in query'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `handle_interrupt'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/mysql2-0.3.21/lib/mysql2/client.rb:79:in `query'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:309:in `block in execute'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:309:in `execute'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/mysql2_adapter.rb:248:in `exec_insert'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:108:in `insert'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation.rb:64:in `insert'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/persistence.rb:524:in `_create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/counter_cache.rb:139:in `_create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/locking/optimistic.rb:75:in `_create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attribute_methods/dirty.rb:133:in `_create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/callbacks.rb:306:in `block in _create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:117:in `call'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:505:in `call'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:92:in `__run_callbacks__'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:778:in `_run_create_callbacks'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/callbacks.rb:306:in `_create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/timestamp.rb:57:in `_create_record'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/persistence.rb:504:in `create_or_update'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/callbacks.rb:302:in `block in create_or_update'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:117:in `call'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:505:in `call'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:92:in `__run_callbacks__'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:778:in `_run_save_callbacks'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/callbacks.rb:302:in `create_or_update'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/persistence.rb:120:in `save'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/validations.rb:37:in `save'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/attribute_methods/dirty.rb:21:in `save'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:286:in `block (2 levels) in save'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:220:in `transaction'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:286:in `block in save'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:301:in `rollback_active_record_state!'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:285:in `save'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/protected_attributes-1.1.4/lib/active_record/mass_assignment_security/persistence.rb:46:in `create'

        from /usr/local/redmine/app/models/repository/git.rb:218:in `save_revision'

        from /usr/local/redmine/app/models/repository/git.rb:207:in `block (2 levels) in save_revisions'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:220:in `transaction'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:277:in `transaction'

        from /usr/local/redmine/app/models/repository/git.rb:204:in `block in save_revisions'

        from /usr/local/redmine/app/models/repository/git.rb:203:in `each'

        from /usr/local/redmine/app/models/repository/git.rb:203:in `save_revisions'

        from /usr/local/redmine/app/models/repository/git.rb:153:in `fetch_changesets'

        from /usr/local/redmine/app/models/repository.rb:346:in `block (2 levels) in fetch_changesets'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each'

        from /usr/local/redmine/app/models/repository.rb:344:in `block in fetch_changesets'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/relation/delegation.rb:46:in `each'

        from /usr/local/redmine/app/models/repository.rb:343:in `fetch_changesets'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62:in `<top (required)>'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62:in `eval'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/runner.rb:62:in `<top (required)>'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:123:in `require'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:123:in `require_command!'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:90:in `runner'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'

        from /usr/local/rvm/rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>'

        from bin/rails:4:in `require'

        from bin/rails:4:in `<main>'


* Error point: Changeset process

* ./app/models/repository.rb
   If you need to isolated test. Add "fetch_changesets_dbg" function like "fetch_changesets" function.
   And test with next command
  "rails runner "Repository.fetch_changesets_dbg" -e production"

* ./app/models/repository/git.rb (if you use git)
  Fix : 

add fuction

def get_ascii_only(str_a)

    ret_val = ""

    str_a.each_byte do |c|

      $char = c.chr

      if $char.ascii_only?

         ret_val += $char

      end

    end

    return ret_val

  end

  private :get_ascii_only

 

Modify revision function

def save_revision(rev)

    parents = (rev.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact

    begin

      changeset = Changeset.create(

              :repository   => self,

              :revision     => rev.identifier,

              :scmid        => rev.scmid,

              :committer    => rev.author,

              :committed_on => rev.time,

              :comments     => rev.message,

              :parents      => parents

              )

    rescue

      new_mesg = get_ascii_only(rev.message)

      changeset = Changeset.create(

              :repository   => self,

              :revision     => rev.identifier,

              :scmid        => rev.scmid,

              :committer    => rev.author,

              :committed_on => rev.time,

              :comments     => new_mesg,

              :parents      => parents

              )

    end

    unless changeset.new_record?

        rev.paths.each { |change| changeset.create_change(change) }

    end

    changeset

  end

 



Comments

Popular posts from this blog

[scapy] Linux-Cooked pcap to ethernet

# The pcap file formatted by "Linux cooked" # tcpdump -r myfile.pcap -nn reading from file event1.pcap, link-type LINUX_SLL (Linux cooked) ... ... # step1. read myfile.pcap pkts = rdpcap("myfile.pcap"); # step2. read myfile.pcap pkts = [Ether(src='00:11:22:33:44:55', dst='22:33:44:55:66:77')/pkt[1:] for pkt in pkts] # step3. modify IP address and recalculate chksum for pkt in pkts:  pkt[1].dst='192.168.1.10';  pkt[1].src='192.168.1.1';  del pkt[IP].chksum  del pkt[UDP].chksum # step4. packet send sendp(pkts[0]); # step5. save pcap  wrpcap("output.pcap",pkts); # tcpdump -r output.pcap -nn reading from file output.pcap, link-type EN10MB (Ethernet) ... ... # pkt[1:] : It means IP layer 1) Before: Linux cooked / IP / UDP / UDP-Data 2) After: Ethernet / IP / UDP / UDP-Data

[WordPress] Change https redirect in DB.

If you make an https redirect without thinking about SSL configuration: Check DB SELECT * from wp_options where option_name IN ('siteurl', 'home'); Update UPDATE wp_options SET option_value = REPLACE(option_value, 'https://your_domain', 'http://your_domain') WHERE option_name IN ('siteurl', 'home');

[bash-script/gcc] check warning of make within git-diff of commit

When you need check "make warning" in specific commits, you can use this script to check just in some commits. This script takes some steps. step1. You must know your commit hash. : like abcd1234 step2. Checkout to your commit.  Like this, git checkout abcd1234. step3. You need output file that run make.  Try to run command "make &> myoutput" step4. Then run this. ./new_warning.sh abcd1234 myoutput You can download this script :  new_warning.sh