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

Fix encoding detection error for MySQL applications using a connection proxy #3313

Merged

Conversation

codealchemy
Copy link
Contributor

Issue

Applications using MySQL with DB connection proxies (seen when using active_record_host_pool, but may apply to others that employ the same pattern) cannot currently use RailsAdmin's export feature, as instance_variable_get returns nil - resulting in a NoMethodError when #encoding is called from the template after a user clicks to export from a list.

Proposed change

raw_connection returns the same connection as the @connection instance variable, and works with Delegators that wrap the connection. raw_connection itself is supported across all maintained versions of Rails, and resolves the issue mentioned above.

Applications using MySQL and DB connection proxies (such as [active_record_host_pool](https://github.com/zendesk/active_record_host_pool/blob/76c244ddb1d7b5736fe0d043b98e33026b9c170f/lib/active_record_host_pool/connection_proxy.rb)) cannot currently use RailsAdmin's export feature, as `instance_variable_get` returns `nil` - resulting in a `NoMethodError` when `#encoding` is called [from the template](https://github.com/sferik/rails_admin/blob/73ac02f7c375f2f446ceb212615ef9056c9cd587/app/views/rails_admin/main/export.html.haml#L59) after a user clicks to export from a list.

`raw_connection` returns the same connection as the `@connection` instance variable, and works with `Delegator`s that wrap the connection. `raw_connection` itself is [supported across all maintained versions of Rails](https://apidock.com/rails/v6.0.0/ActiveRecord/ConnectionAdapters/AbstractAdapter/raw_connection), and resolves the issue mentioned above.
@codealchemy
Copy link
Contributor Author

codealchemy commented Oct 9, 2020

📝 CI failure appears unrelated (jruby-9.2.13.0|rails_6.0|mongoid - seed 20662).

@mshibuya mshibuya merged commit a2fd16b into railsadminteam:master Oct 11, 2020
@mshibuya
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants