Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Databases.rake does not find 'encoding' var correctly

#940

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.

Reported by science · August 30th, 2008 @ 06:08 AM

State: stale
Milestone: 2.x
Assigned to: Tarmo Tänav Tarmo Tänav
Importance: none

Activity

  1. science
    science
    • 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 }}}

    August 30th, 2008 @ 08:00 AM

  2. science
    science

    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
    

    August 30th, 2008 @ 08:02 AM

  3. science
    science

    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
    

    August 30th, 2008 @ 08:23 AM

  4. Pratik
    Pratik
    • 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!

    December 20th, 2008 @ 05:13 PM

  5. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • State changed from incomplete to stale

    January 22nd, 2010 @ 08:52 AM