Skip to content

Rails 5.2 doesn't work with Ruby 3.0 #40938

@st0012

Description

@st0012

Description

Ruby 3.0 introduced some argument rule changes, which are handled properly in Rails 6.0 and 6.1. But in Rails 5.2, we can still see issues in active_record's create_table method.

Steps to reproduce

This is part of the Rails' bug report template for active_record

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", "~> 5.2.4"
  gem "sqlite3"
end

require "active_record"
require "logger"

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
  end
end

Expected behavior

It should work.

Actual behavior

-- create_table(:posts, {:force=>true})
/Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:290:in `create_table': wrong number of arguments (given 2, expected 1) (ArgumentError)
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:871:in `block in method_missing'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:840:in `block in say_with_time'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/3.0.0/benchmark.rb:293:in `measure'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:840:in `say_with_time'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/migration.rb:860:in `method_missing'
        from report.rb:22:in `block in <main>'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/schema.rb:50:in `instance_eval'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/schema.rb:50:in `define'
        from /Users/st0012/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-5.2.4.4/lib/active_record/schema.rb:46:in `define'
        from report.rb:21:in `<main>'

System configuration

Rails version: 5.2.4.4

Ruby version: 3.0.0

Other notes

This refactoring commit solved the issue for Rails 6 and beyond. So I think a solution could be backporting this commit to the 5-2-stable branch. Or if 5.2 versions will not be supported with Ruby 3.0, changing gemspecs to make that clear would be good as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions