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.

Postgres ActiveRecord adapter merges UTF8 encoding as symbol instead of string in create_database

#941

Synopsis: The postgressql-adapter create_datbase function does a reverse_merge on the database options - trying to set a default value of "utf8" - however the incoming keys are all strings and the adapter sets a symbol ':encoding' which results in utf8 being used in all cases.

This is causing problems for me after upgrading to v2.1 b/c when the test database is recreated it is created as 'utf8' format which is incorrect for my situation.

Analysis: Line 490 in file 'active-record-2.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb' is currently:

< options = options.reverse_merge(:encoding => "utf8")

It should be changed to be:

options = options.reverse_merge('encoding' => "utf8")

Or the keys should be locally symbolized before messing with them (they are currently symbolized just after this line!).

I'm sorry I'm not able to submit a patch - I don't use git yet (I just got to the point where I could submit patches in SVN and now git!) [smile]

I hope this bug report is sufficient - I think this is a very easy / low impact thing to fix. Contact me anytime with questions.

I think this bug will break any postgresql user who isn't using a utf8 database and who has tests which fail if utf8 is the format of the test database.

Reported by science · August 30th, 2008 @ 07:28 AM

State: incomplete
Milestone: 3.x
Assigned to: Tarmo Tänav Tarmo Tänav
Importance: none

Activity

  1. science
    science

    There is a related ticket to this one: http://rails.lighthouseapp.com/p...

    In order to fix both problems, I think the following monkey patch does the trick. However, I have the patch from the other ticket and this one running in the environment.rb file (after the regular Initializer section runs):

    
    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:25 AM

  2. science
    science

    Note - from my last comment, it sounds like I'm not sure that the above patch works - it is working for me. What's not clear is that it effectively fixes both tickets. It definitely corrects the defect described in this ticket.

    August 30th, 2008 @ 08:27 AM

  3. Pratik
    Pratik
    • Assigned user set to Tarmo Tänav
    • State changed from new to incomplete

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

    Thanks!

    December 20th, 2008 @ 05:13 PM

  4. Ryan Bigg
    Ryan Bigg

    science, how's your git now? Please submit a patch if you could.

    April 10th, 2010 @ 08:56 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  6. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 01:54 AM

  7. bingbing