Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Arel 0.3.2 broke non-standard column types

#4270

I have smallint and UUID columns in my PostgreSQL database.
After ActiveRecord bumped the Arel dependency today, all of my unit test started to fail like this:

<ActiveRecord::RecordInvalid> exception expected but was
Class: < NotImplementedError >
Message: <"Column type `` is not currently handled">
---Backtrace---
/Users/perw/.bundle/ruby/1.8/bundler/gems/arel-8151ac946644aab31601d7c0ed944eb9d7ea1e6b-master/lib/arel/engines/sql/attributes.rb:18:in `for'
/Users/perw/.bundle/ruby/1.8/bundler/gems/arel-8151ac946644aab31601d7c0ed944eb9d7ea1e6b-master/lib/arel/engines/sql/relations/table.rb:46:in `attributes'
/Users/perw/.bundle/ruby/1.8/bundler/gems/arel-8151ac946644aab31601d7c0ed944eb9d7ea1e6b-master/lib/arel/engines/sql/relations/table.rb:45:in `collect'
/Users/perw/.bundle/ruby/1.8/bundler/gems/arel-8151ac946644aab31601d7c0ed944eb9d7ea1e6b-master/lib/arel/engines/sql/relations/table.rb:45:in `attributes'
/Users/perw/.bundle/ruby/1.8/bundler/gems/arel-8151ac946644aab31601d7c0ed944eb9d7ea1e6b-master/lib/arel/algebra/relations/relation.rb:100:in `find_attribute_matching_name'

I guess the problem is here:
http://github.com/rails/arel/commit/83c27c0b5e2e341307b7a160d831fb9...

Maybe it should default to cast to String instead of raising an exeption?

Reported by Tuxie · March 25th, 2010 @ 10:15 PM

State: resolved
Milestone: 3.0.2
Assigned to: Emilio Tagua Emilio Tagua
Importance: High

Activity

  1. José Valim
    José Valim
    • Assigned user set to Emilio Tagua
    • Milestone cleared.

    March 27th, 2010 @ 12:09 PM

  2. Ernie Miller
    Ernie Miller
    • Tag changed from arel to arel, patch, postgresql

    The types that Arel handles are the only ones that should ever show up based on a call to Column#type or a subclass because of the simplified_types call in ActiveRecord::ConnectionAdapters::Column.initialize.

    Based on the simplified_types method in active_record/connection_adapters/postgresql_adapter.rb it looks like the problem is that no mapping exists for those column types. This seems to be a problem with the PostgreSQL adapter, not Arel. Can you try the attached patch and see if the problem goes away? I don't run PostgreSQL here, so I haven't tested it, but I think it should do the trick.

    March 31st, 2010 @ 08:54 PM

  3. Emilio Tagua
    Emilio Tagua
    • State changed from new to incomplete

    Ernie, the patch looks good can you add tests?

    March 31st, 2010 @ 09:35 PM

  4. Ernie Miller
    Ernie Miller
    • Tag changed from arel, patch, postgresql to arel, patch, postgresql, tests

    Sure. Here you go.

    March 31st, 2010 @ 10:07 PM

  5. Ernie Miller
    Ernie Miller

    Adding the file. Was showing the old one for me. Probably just caching on my end but want to be sure.

    March 31st, 2010 @ 10:09 PM

  6. Ernie Miller
    Ernie Miller

    Adding the file. Was showing the old one for me. Probably just caching on my end but want to be sure.

    March 31st, 2010 @ 10:10 PM

  7. Ernie Miller
    Ernie Miller

    Adding the file. Was showing the old one for me. Probably just caching on my end but want to be sure.

    March 31st, 2010 @ 10:10 PM

  8. Ernie Miller
  9. Repository
    Repository
    • State changed from incomplete to resolved

    March 31st, 2010 @ 11:16 PM

  10. garrett
    garrett

    I'm getting this error now also. Trying to save PostGIS geometry types back to the database. String would be the correct way to handle these columns as they get shuffled in and out normally as Hex.

    NotImplementedError: Column type is not currently handled<br/>

    from /Users/garrett/.rvm/gems/ruby-1.9.2-head/gems/arel-0.3.3/lib/arel/engines/sql/attributes.rb:18:in `for'
    from /Users/garrett/.rvm/gems/ruby-1.9.2-head/gems/arel-0.3.3/lib/arel/engines/sql/relations/table.rb:46:in `block in attributes'
    

    April 21st, 2010 @ 02:46 AM

  11. garrett
    garrett

    here's a patch that should work

    April 21st, 2010 @ 03:06 AM

  12. gucki
    gucki

    The problems still occurs when using custom data types, which is quite common when using pgsql.

    Either there should be a way to easily add custom datatypes with their mapping or the adapter should fallback to :string for unknown types.

    May 15th, 2010 @ 05:20 PM

  13. jdguyot
    jdguyot

    Same problem here. I'm currently migrating our app from Rails 2.3.5 to 3.0b4. We use custom pgsql types which is a really common thing.

    class CreateModel < ActiveRecord::Migration
      def self.up
        # Create a custom column type
        execute %{ CREATE TYPE custom_column_type AS ENUM ('item1', 'item2'); }
        
        create_table :models do |t|
          t.column    :custom_column, :custom_column_type
          t.timestamps
        end
      end
    
      def self.down
        drop_table :models
        execute %{ DROP TYPE custom_column_type; }
      end
    end
    

    I see the same stack than above:

    NotImplementedError: Column type `` is not currently handled
        vendor/gems/arel-0.4.0/lib/arel/engines/sql/attributes.rb:18:in `for'
        vendor/gems/arel-0.4.0/lib/arel/engines/sql/relations/table.rb:47:in `attributes'
        vendor/gems/arel-0.4.0/lib/arel/engines/sql/relations/table.rb:46:in `collect'
        vendor/gems/arel-0.4.0/lib/arel/engines/sql/relations/table.rb:46:in `attributes'
        vendor/gems/arel-0.4.0/lib/arel/algebra/relations/relation.rb:87:in `[]'
        vendor/gems/activerecord-3.0.0.beta4/lib/active_record/base.rb:1776:in `arel_attributes_values'
        ...
    

    June 23rd, 2010 @ 09:54 PM

  14. Mordekai
    Mordekai
    • Importance changed from to High

    I've got the same problem with Postgres's tsvector type, which is now a standard data type. This issue seems to be as marked resolved prematurely: Some way to add new data types without patching postgresql_adapter.rb is needed, perhaps using a hash added to /config/initializers/postgres_init.rb.

    July 15th, 2010 @ 06:23 PM

  15. Steve Madsen
    Steve Madsen
    • State changed from resolved to incomplete

    Adding to the chorus, I see the same behavior with a column of type "earth", from the earthdistance contrib module. I don't actually care about updating this column from within the Rails app, but I do need access to the other columns in the table. [state:incomplete]

    August 10th, 2010 @ 04:04 AM

  16. Jeremy Kemper
  17. Emilio Tagua
    Emilio Tagua
    • State changed from incomplete to resolved

    Hey,

    I think this was solved here:

    #5477 Arel won't let ActiveRecord query against tables that have columns it doesn't...

    Commit here:

    http://github.com/rails/arel/commit/33445ba4c7729970ff8840634c92009...

    I'm closing the ticket, feel free to reopen it you find it's still not working.

    September 21st, 2010 @ 08:19 PM

  18. Jeremy Kemper