fix for #10613 . This PR is still WIP. #12519

Closed
wants to merge 2 commits into
from

Projects

None yet

6 participants

@neerajdotname
Ruby on Rails member

I'm sending this PR in response to this comment. #10613 (comment)

I'm not sure if this is the best fix. And it does not have any test yet.

I guess PR will get more scrutiny and comments compared to a branch lying in my repo.

@rafaelfranca rafaelfranca commented on the diff Oct 13, 2013
...b/active_record/connection_adapters/postgresql/oid.rb
end
def type_cast(value)
+ return value unless @typecast
@rafaelfranca
rafaelfranca Oct 13, 2013

Why do we need this guard?

@neerajdotname
neerajdotname Oct 13, 2013

@rafaelfranca I'm not able to recall why I added that. :-(

@rafaelfranca rafaelfranca commented on the diff Oct 13, 2013
...d/connection_adapters/postgresql/schema_statements.rb
# Limit, precision, and scale are all handled by the superclass.
column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod|
oid = OID::TYPE_MAP.fetch(oid.to_i, fmod.to_i) {
OID::Identity.new
}
+ if !typecast && ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Array === oid && ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::Identity === oid.subtype
@rafaelfranca
rafaelfranca Oct 13, 2013

Instead of type checking we should define an API with a default implementation and implement it in a different way on Array

@neerajdotname
neerajdotname Oct 14, 2013

@rafaelfranca will look into it this week.

@nfm

@neerajdotname Thanks for pinging me about this. Your fix looks promising but I'm not at all familiar with this part of AR so it would be good to get a second opinion.

My previous db/schema.rb had the following offending line (caused by running a migration on vanilla Rails 4.0.0):

t.text "languages", default: ["en"], array: true

Running db:schema:load with that line in my schema.rb was raising "undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition:0x007f1f59045310>".

After checking out your branch and running bundle exec rake db:migrate, my schema.rb was corrected to:

t.text "languages", default: "{en}", array: true

And I can now run bundle exec rake db:schema:load without an exception.

👍 Works for me!

@neerajdotname
Ruby on Rails member

@nfm good to know that the fix worked for you. Thanks for the feedback. Will try to get a fix into master soon.

@smostovoy

@neerajdotname Thanks for PR! Could you finish it?

@senny
Ruby on Rails member

@neerajdotname I'm closing this one out of inactivity and in favor of #14509. Thank you for your work 💛

@senny senny closed this Mar 29, 2014
@neerajdotname
Ruby on Rails member

@senny sure. Sorry I have not been able to work on Rails issues much lately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment