Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord TypeError: can't dup Symbol #9808

Closed
DEfusion opened this issue Mar 19, 2013 · 5 comments
Closed

ActiveRecord TypeError: can't dup Symbol #9808

DEfusion opened this issue Mar 19, 2013 · 5 comments

Comments

@DEfusion
Copy link

Running a query via select_all on a custom mysql2 connection is throwing a TypeError: can't dup Symbol in ActiveRecord::Result line 33.

The mysql2 connection is being made via the following:

ActiveRecord::Base.mysql2_connection(
    :host => Settings.import_db[:hostname],
    :username => Settings.import_db[:username],
    :password => Settings.import_db[:password],
    :database => Settings.import_db[:database],
    :port => Settings.import_db[:port],
    :reconnect => true
)

Issue present in 3.2.13

@schneems
Copy link
Member

Are you specifying your host, username, password, database, or port as a symbol? Without exposing sensitive information can you run

$ bundle open activerecord

Then modify line 33 to be

columns = @columns.map { |c| 
  puts c.inspect
  c.dup.freeze 
}

Then try to initialize a DB connection and paste the output here? Don't forget to change that line back when done.

@senny
Copy link
Member

senny commented Apr 9, 2013

@DEfusion is this still a problem? Did the advice from @schneems help?

@muffinista
Copy link

I work with @DEfusion, and this is still a problem for us. We're communicating with a remote, non-Rails database via a custom mysql connection with symbolize_keys set like so:

    Mysql2::Client.default_query_options.merge!(
        :symbolize_keys => true
    )

I put a line similar to the one @schneems suggested. All of the output from Rails is arrays of strings like this:

["id", "account_id", "test", "created_at", "updated_at", "state"]

While arrays from our remote db are of symbols like so:

[:id, :domain, :enabled]

I can fix this problem by changing the map to look like this:

      columns = @columns.map { |c| c.is_a?(Symbol) ? c : c.dup.freeze }

And I can submit a PR for that, but it's not clear to me that it's actually the best solution.

@rafaelfranca
Copy link
Member

@muffinista could you provide the pull request so we can discuss the solution?

@rafaelfranca
Copy link
Member

Closed as stale. If you think it is still an issue let us know

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

No branches or pull requests

5 participants