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

valid_type? should accept only supported types #28220

Merged

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Feb 28, 2017

valid_type? is used in schema dumper to determine if a type is
supported. So if valid_type?(:foobar) is true, it means that schema
dumper is allowed to create t.foobar. But it doesn't work. I think
that valid_type? should accept only supported types.

https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L135-L142

  columns.each do |column|
    raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
    next if column.name == pk
    type, colspec = @connection.column_spec(column)
    tbl.print "    t.#{type} #{column.name.inspect}"
    tbl.print ", #{format_colspec(colspec)}" if colspec.present?
    tbl.puts
  end

`valid_type?` is used in schema dumper to determine if a type is
supported. So if `valid_type?(:foobar)` is true, it means that schema
dumper is allowed to create `t.foobar`. But it doesn't work. I think
that `valid_type?` should accept only supported types.

https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L135-L142

```ruby
  columns.each do |column|
    raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
    next if column.name == pk
    type, colspec = @connection.column_spec(column)
    tbl.print "    t.#{type} #{column.name.inspect}"
    tbl.print ", #{format_colspec(colspec)}" if colspec.present?
    tbl.puts
  end
```
@rafaelfranca
Copy link
Member

hmmm, this is going in the opposite direction that the comment on activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb . Did you check why it was made that way?

@kamipo
Copy link
Member Author

kamipo commented Mar 1, 2017

Yes, the comment added at #9984 (related #9204, #9656) but it is incorrect I think. Even though sqlite database supports any sql_types, schema dumper is not. valid_type? checks type, not sql_type. valid_type?(:foobar) should not be accepted. :foobar is not a valid type for schema dumper.

@rafaelfranca rafaelfranca merged commit 22e33e4 into rails:master Mar 1, 2017
@kamipo kamipo deleted the valid_type_accept_only_supported_types branch March 2, 2017 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants