bibendi / activerecord-postgres_enum

Integrate PostgreSQL's enum data type into ActiveRecord's schema and migrations.
MIT License
361 stars 24 forks source link

Rails 7 rc1: undefined method 'ArgumentError' #52

Closed SeanLF closed 2 years ago

SeanLF commented 2 years ago

Describe the bug Tests fail on Rails 7 rc1

To Reproduce Steps to reproduce the behavior:

Expected behavior No errors occur

Additional context https://github.com/SeanLF/activerecord-postgres_enum/runs/4438226882?check_suite_focus=true

An error occurred while loading spec_helper.
Failure/Error:
  create_table :tracks do |t|
    t.enum "mood", enum_name: :moods
  end

NoMethodError:
  undefined method `ArgumentError' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x000055e78e4578f8>
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:572:in `type_to_sql'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:16:in `type_to_sql'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:32:in `visit_ColumnDefinition'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:13:in `accept'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:47:in `block in visit_TableDefinition'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:47:in `map'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:47:in `visit_TableDefinition'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_creation.rb:13:in `accept'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_statements.rb:325:in `create_table'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/migration.rb:931:in `block in method_missing'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/migration.rb:899:in `block in say_with_time'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/migration.rb:899:in `say_with_time'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/migration.rb:920:in `method_missing'
# ./spec/internal/db/schema.rb:6:in `block in <top (required)>'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/schema.rb:50:in `instance_eval'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/schema.rb:50:in `define'
# /bundle/ruby/2.7.0/gems/activerecord-7.0.0.rc1/lib/active_record/schema.rb:46:in `define'
# ./spec/internal/db/schema.rb:3:in `<top (required)>'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion/database/load_schema.rb:26:in `load'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion/database/load_schema.rb:26:in `load_ruby_schema'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion/database/load_schema.rb:15:in `call'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion/database/load_schema.rb:7:in `call'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion/database.rb:18:in `setup'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion.rb:62:in `block in include_database'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:445:in `instance_exec'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:445:in `block in make_lambda'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:199:in `block (2 levels) in halting'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:687:in `block (2 levels) in default_terminator'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:686:in `catch'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:686:in `block in default_terminator'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:200:in `block in halting'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:595:in `block in invoke_before'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:595:in `each'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:595:in `invoke_before'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/callbacks.rb:106:in `run_callbacks'
# /bundle/ruby/2.7.0/gems/activesupport-7.0.0.rc1/lib/active_support/reloader.rb:88:in `prepare!'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/application/finisher.rb:73:in `block in <module:Finisher>'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/initializable.rb:32:in `instance_exec'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/initializable.rb:32:in `run'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/initializable.rb:61:in `block in run_initializers'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/initializable.rb:60:in `run_initializers'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/application.rb:369:in `initialize!'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/railtie.rb:224:in `public_send'
# /bundle/ruby/2.7.0/gems/railties-7.0.0.rc1/lib/rails/railtie.rb:224:in `method_missing'
# /bundle/ruby/2.7.0/gems/combustion-1.3.5/lib/combustion.rb:54:in `initialize!'
# ./spec/spec_helper.rb:8:in `<top (required)>'
No examples found.
bibendi commented 2 years ago

Hi! Thanks for the reporting!

muxcmux commented 2 years ago

The reason you are getting this error is because Rails 7 rc1 just added this: https://github.com/rails/rails/commit/4eef348584087c81f1e32ad971baf632b0149cd4#diff-0989923401a81fa4208ffc75f8e8622d20353373f9ba38c373d7ff15485b20b4

which is basically adding support for custom enums directly in the postgresql AR adapter. It adds the create_enum method in migrations and requires an enum_type option that points to the name of the enum; kinda like enum_name in this gem's speak.

That's just a quick scan I had and didn't look properly how to resolve this. It seems now that create_enum is provided by both rails and this gem, so not entirely sure what the right course of action is.

bibendi commented 2 years ago

@muxcmux Thank you for the link! I see that support for enums is very poor. So I decided to override that feature. The PR is still WIP. I'm going to continue working on it next week.

muxcmux commented 2 years ago

Yeah, that addition to create_enum in Rails seems quite basic. There's no support for removing an enum once added or updating an enum's values.

Thanks for jumping on top of this!

bibendi commented 2 years ago

Just released https://github.com/bibendi/activerecord-postgres_enum/releases/tag/v2.0.0 Sorry for the breaking changes.