This project is archived and is in readonly mode.
Postgres ActiveRecord adapter merges UTF8 encoding as symbol instead of string in create_database
Reported by science | August 30th, 2008 @ 07:28 AM | in 3.x
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.
Comments and changes to this ticket
-
science August 30th, 2008 @ 08:25 AM
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
-
science August 30th, 2008 @ 08:27 AM
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.
-
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 + failing test case - http://rails.lighthouseapp.com/p... ?
Thanks!
-
Ryan Bigg April 10th, 2010 @ 08:56 AM
science, how's your git now? Please submit a patch if you could.
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>
People watching this ticket
Referenced by
- 940 Databases.rake does not find 'encoding' var correctly This is a mess. Sorry - to late at night. The code above ...