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

Call ignore_model_if before RbsRails::ActiveRecord.generatable? #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kyanagi
Copy link

@kyanagi kyanagi commented Oct 6, 2024

RbsRails::ActiveRecord.generatable? may raise an exception.
For example, this occurred when using ActiveType::Object.

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "activerecord"
  gem "sqlite3"
  gem "rbs_rails"
  gem "active_type"
end

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

class X < ActiveType::Object
end

p RbsRails::ActiveRecord.generatable?(X)
% ruby -v ~/work/rbs_rails_test.rb
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin22]
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
/Users/ani/.rbenv/versions/3.3.5/lib/ruby/3.3.0/json/common.rb:3: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add ostruct to your Gemfile or gemspec to silence this warning.
/Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1864:in `data_source_sql': NotImplementedError (NotImplementedError)
        from /Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:52:in `tables'
        from /Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:62:in `rescue in table_exists?'
        from /Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:59:in `table_exists?'
        from /Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rbs_rails-0.12.0/lib/rbs_rails/active_record.rb:7:in `generatable?'
        from /Users/ani/work/rbs_rails_test.rb:18:in `<main>'
/Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:1864:in `data_source_sql': NotImplementedError (NotImplementedError)
        from /Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:60:in `table_exists?'
        from /Users/ani/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/rbs_rails-0.12.0/lib/rbs_rails/active_record.rb:7:in `generatable?'
        from /Users/ani/work/rbs_rails_test.rb:18:in `<main>'

If we call ignore_model_if before generatable?, we can handle such cases by adding models that cause errors to ignore_model_if.

RbsRails::ActiveRecord.generatable? may raise an exception.
For example, this occurred when using ActiveType::Object. https://github.com/makandra/active_type

If we call ignore_model_if before generatable?, we can handle such cases
by adding models that cause errors to ignore_model_if.
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

Successfully merging this pull request may close these issues.

1 participant