This project is archived and is in readonly mode.

#940 ✓stale
science

Databases.rake does not find 'encoding' var correctly

Reported by science | August 30th, 2008 @ 06:08 AM | in 2.x

Synopsis: Specifying 'encoding' value in database.yml does not affect the encoding chosen for creating the test database via databases.rake

Analysis: Line 46 of rails-2.1.0/lib/tasks/databases.rake is wrong. It is looking for a symbol in config hash but all the keys are strings.

Line 46 is:

<< @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'

Line 46 should be:

@encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'

I can't see any reason why this should be a symbol and I don't know what would break. I do not have a rails testing installation to run tests and I'm not yet up on Git (still with SVN) so I can't submit a patch. Apologies for being a retard.

I hope this submission is easy to understand and patch. I suspect there is no consequence to this change b/c the config hash is full of strings so I don't know how anyone could be affected.

Write anytime with questions or requests for additional info.

Comments and changes to this ticket

  • science

    science August 30th, 2008 @ 08:00 AM

    • Tag changed from 2.1, config, database.yml, databases.rake, encoding to 2.1, bug, config, database.yml, databases.rake, encoding

    In case anyone else is running into this, here's a monkey patch which can be included in environment.rb that seems to resolve the problem for now (I basically just symbolize the option keys before the actual method sees them):

    {{{ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter old_create_database = self.instance_method(:create_database) define_method(:create_database) do |name, *args|

    args[0] = (args[0] || {}).symbolize_keys
    old_create_database.bind(self).call(name, *args)
    
    

    end end }}}

  • science

    science August 30th, 2008 @ 08:02 AM

    Oh goodness - lighthouse uses different tags from trac - sorry about that. Here's that code block for environment.rb again:

    
    class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
      old_create_database = self.instance_method(:create_database)
      define_method(:create_database) do |name, *args|
        args[0] = (args[0] || {}).symbolize_keys
        old_create_database.bind(self).call(name, *args)
      end
    end
    
  • science

    science August 30th, 2008 @ 08:23 AM

    This is a mess. Sorry - to late at night. The code above is for the related ticket: http://rails.lighthouseapp.com/p...

    The correct patch in environment.rb (below the regular Initializer section) to work around this problem is:

    
    Rails::Initializer.run do |config|
      # this works around a bug in databases.rake: http://rails.lighthouseapp.com/projects/8994/tickets/940-databasesrake-does-not-find-encoding-var-correctly#ticket-940-1
      # databases.rake will use an env var in place of encoding value
      ENV['CHARSET'] = config.database_configuration[RAILS_ENV]["encoding"]
    end
    
  • Pratik

    Pratik December 20th, 2008 @ 05:13 PM

    • Assigned user set to “Tarmo Tänav”
    • State changed from “new” to “incomplete”

    Could you please submit a patch - http://rails.lighthouseapp.com/p... ?

    Thanks!

  • Prem Sichanugrist (sikachu)

    Prem Sichanugrist (sikachu) January 22nd, 2010 @ 08:52 AM

    • State changed from “incomplete” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages