This project is archived and is in readonly mode.
ActiveRecord Beta 4 does not understand most postgres data types
Reported by Jeff Dean | July 26th, 2010 @ 06:24 AM
I have a postgres database with a table that has a column of
type search_vector
(and other postgres-specific data
geometry data types). Up to Rails 2.3.8 everything was fine, but
when I tried upgrading to Rails beta 4 with Arel 0.4.0 I can no
longer perform basic queries. The error I get is:
Column type `` is not currently handled
The offending code is in
lib/arel/engines/sql/attributes.rb
:
module Arel
module Sql
module Attributes
def self.for(column)
case column.type
when :string then String
when :text then String
when :integer then Integer
when :float then Float
when :decimal then Decimal
when :date then Time
when :datetime then Time
when :timestamp then Time
when :time then Time
when :binary then String
when :boolean then Boolean
else
raise NotImplementedError, "Column type `#{column.type}` is not currently handled"
end
end
# ...
end
end
end
The column in question looked like this:
#<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x34d4a24 @precision=nil, @null=true, @primary=nil, @sql_type="tsvector", @limit=nil, @default=nil, @type=nil, @name="search_vector", @scale=nil>
So there are a few parts to fixing this bug:
- fixing the useless error message when it can't understand a column type
- making AR use the postgres adapter's column types that were used in previous versions of rails
I'd like to fix this, but before I dig in I'd like some feedback on how. A few things that come to mind are:
- Find all places where
arel_attributes_values
is used and instead call the adapter-specific methods - Create a new Arel Engine for postgres that inherits from the SQL engine, and overrides methods as necessary (then set the correct engine for each connection)
- Move all the adapter-specific code to Arel
- Making it possible for developers to register their own datatype mapppings without mucking with private apis
If you have an idea what the long-term vision is for making AR work across adapters please let me know. Otherwise, I'll fix this the quickest way I can find and submit a patch. Until then, anybody taking advantage of postgres's other data types is hosed.
Comments and changes to this ticket
-
Steve Madsen August 16th, 2010 @ 03:22 AM
This ticket sounds very similar to #4270.
Rails 3.0 RC is unable to save models that make use of Postgres custom data types. Reading is fine; columns with a custom type are treated as String, but writing, even when the custom type column is unchanged, raises the exception reported here.
I made a small change to
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
, around line 119, essentially never delegating type simplification to the superclass. If a specific mapping can't be determined, I always use:string
. This fixes my immediate problem, where I don't care about working with the custom type column. (In my case, the custom type is optimized for PostgreSQL indexing and is maintained by a trigger.)Fixing the ARel issue with the error message looks simple. Instead of complaining about
column.type
, it should report thecolumn.sql_type
.I'm happy to work up patches for both of these one-liners, but given the stagnation on #4270, I'd like some direction before taking the time to do so.
-
Andrea Campi October 17th, 2010 @ 01:24 PM
Can you verify whether this is still an issue after the fix for #5477 has been committed?
-
Santiago Pastorino February 2nd, 2011 @ 04:29 PM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:29 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>