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

"Cannot find corresponding type for inet" #121

Closed
george-carlin opened this issue Dec 30, 2016 · 4 comments
Closed

"Cannot find corresponding type for inet" #121

george-carlin opened this issue Dec 30, 2016 · 4 comments

Comments

@george-carlin
Copy link

I'm using the bleeding edge version of rom-sql to get access to some new features, and this required pulling in the bleeding edge versions of some other rom gems to make the dependencies resolve:

rom-sql-c32f2e91e533
rom-5b338e873884
rom-repository-1bf9da460277
rom-support-673256b41457

But now when I try to start my server I get an error:

/Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:71:in `block in map_type': Cannot find corresponding type for inet (ROM::SQL::UnknownDBTypeError)
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:70:in `fetch'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:70:in `map_type'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/extensions/postgres/inferrer.rb:45:in `map_type'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:58:in `build_type'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:47:in `block in call'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:46:in `map'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema/inferrer.rb:46:in `call'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/relation.rb:42:in `block (2 levels) in inherited'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/schema.rb:219:in `finalize!'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-sql-c32f2e91e533/lib/rom/sql/schema.rb:83:in `finalize!'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize/finalize_relations.rb:54:in `build_relation'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize/finalize_relations.rb:25:in `block (2 levels) in run!'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize/finalize_relations.rb:24:in `each'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize/finalize_relations.rb:24:in `block in run!'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/relation_registry.rb:6:in `initialize'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize/finalize_relations.rb:23:in `new'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize/finalize_relations.rb:23:in `run!'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize.rb:93:in `load_relations'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/setup/finalize.rb:62:in `run!'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/create_container.rb:33:in `finalize'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/create_container.rb:11:in `initialize'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/create_container.rb:52:in `initialize'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/create_container.rb:57:in `new'
    from /Users/george/.rvm/gems/ruby-2.4.0/bundler/gems/rom-5b338e873884/lib/rom/create_container.rb:57:in `container'

I have some inet columns in my PostgreSQL DB; looks like the new version of rom-sql doesn't know how to handle them (although it was working before).

(I'm using version 0.19.0 of the pg gem.)

@george-carlin
Copy link
Author

george-carlin commented Dec 30, 2016

Note: in the meantime I was able to get it working by removing infer: true from my Accounts relation (accounts is the table that has the inet column) and specifying the columns I need explicitly within a schema block, without including the inet columns. This only works because I don't actually care about the inet columns as far as ROM is concerned, so I don't need to include them.

EDIT... wait, nevermind, this doesn't work, I was just on the wrong branch. Disregard!

EDIT no. 2: managed to 'fix' it with the following hack: opened up my local copy of the rom-sql gem, and changed the method map_type in lib/rom/sql/schema/inferrer to the following:

        def map_type(ruby_type, db_type, **_kw)
          ruby_type = :string if db_type.to_s == 'inet' # <- this is the new line
          self.class.ruby_type_mapping.fetch(ruby_type) {
            raise UnknownDBTypeError, "Cannot find corresponding type for #{ruby_type || db_type}"
          }
        end

This is obviously not a long-term solution: use at your own peril.

@solnic
Copy link
Member

solnic commented Dec 30, 2016

I'll tweak inferrer so that it doesn't raise and instead schema will allow you to define missing attributes and if some attributes are still missing during schema finalization, then it will raise.

@solnic solnic closed this as completed in 62502b8 Dec 30, 2016
@solnic
Copy link
Member

solnic commented Dec 30, 2016

If you bundle update then you'll be able to do something like this:

schema(infer: true) do
  attribute :ip, Types::String
end

Assuming :ip is the name of the attribute that fails during inference, this will work now.

@george-carlin
Copy link
Author

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

No branches or pull requests

2 participants