activerecord-cockroachdb-adapter icon indicating copy to clipboard operation
activerecord-cockroachdb-adapter copied to clipboard

unknown variable: "timezone"

Open singpolyma-shopify opened this issue 7 years ago • 1 comments

PG::InternalError: ERROR: unknown variable: "timezone" (ActiveRecord::StatementInvalid) : SET SESSION timezone TO 'UTC'

This seems to be caused by the inherited-from pg code trying to set a variable named timezone on connection start, but cockroach calls this variable time zone

singpolyma-shopify avatar Mar 02 '18 19:03 singpolyma-shopify

It looks like cockroach supports SET SESSION time zone 'UTC' but not SET SESSION timezone 'UTC'

The related lines in the postgres active_record adapter are here:

https://github.com/rails/rails/blob/ef73318e29666786feb00e9e9b3b49a771bb0b73/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L708-L728

I was able to get around this issue by disabling ActiveRecord's automatic timezone management.

Added in my application.rb file:

config.time_zone = 'UTC' 
config.active_record.default_timezone = :local
config.active_record.time_zone_aware_attributes = false

Not ideal, but it keeps me moving until I figure a real patch.

j05h avatar Mar 17 '18 17:03 j05h