bullet
bullet copied to clipboard
Upcase of attributes
My gemfile:
...
ruby 2.5.3
gem 'rails', '~> 5.2.3'
gem 'bullet', '~> 6.0.2'
gem 'odbc_adapter', git: 'https://github.com/GPif/odbc_adapter.git'
...
I have a data intensive web app that uses the above mentioned odbc driver to access a Snowflake DW on the cloud (https://www.snowflake.com).
I configured a connection string on database.yml
and use establish_connection
on the model.
database.yml
snowflake:
adapter: odbc
conn_str: "DRIVER=;
Server=<%= ENV['SNOWFLAKE_SERVER']%>;
Database=<%= ENV['SNOWFLAKE_DATABASE']%>;
Port=<%= ENV['SNOWFLAKE_PORT']%>;
UID=<%= ENV['SNOWFLAKE_UID']%>;
PWD=<%= ENV['SNOWFLAKE_PWD']%>;
Role=<%= ENV['SNOWFLAKE_ROLE']%>;"
model:
class Order < ApplicationRecord
establish_connection(:snowflake)
The snowflake database has about 50 columns, the standard for a business Order type (sku, amount, purchase_date, etc). There is no local schema on the server side, as there are no migrations.
My issue is that since I installed bullet, "something" is uppercasing the primary keys on the query, so queries like SELECT * FROM orders WHERE orders.sku='abc'
are turning into SELECT * FROM order WHERE orders.SKU='abc'
which triggers an error:
NoMethodError (undefined method
SKU' for #Order:0x00007fed5c1d5230):`
A funny thing is that this error only happens when running the rails server and it doesn't occur on the rails console.
I found two solutions for it:
a) Use the around_action
skip_bullet
b) Use a type cast on the class so it becomes this:
And went with a), that way I can control where I want
class Order < ApplicationRecord
establish_connection(:snowflake)
attribute :SKU, :string
It seems like an incompatibility between bullet and the odbc driver, probably something bulllet changes that prevents the odbc driver from downcasing attributes.
I'm leaving this here in case anyone has a similar issue and finds it through google.