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

Defining alias_attribute on simple_enum throws deprecation warning in Rails 7.1 #154

Open
mrudult opened this issue Jan 24, 2024 · 0 comments

Comments

@mrudult
Copy link

mrudult commented Jan 24, 2024

Here's the model:

class DistributorUserSource < ApplicationRecord
  alias_attribute :client_customer_id, :client_userid
  alias_attribute :client_customer_platform, :source

  validates :source, :client_userid, presence: true}

  as_enum :source, [:ONE, :TWO, :THREE], map: :string, source: :source

  belongs_to :distributor_user
  belongs_to :distributor
end

where client_userid and source are database columns.

Failure/Error: self.distributor_user_sources.find_or_initialize_by(source: self.source, source_id: self.source_id, client_userid: self.client_userid, distributor_id: self.distributor_id)

ActiveSupport::DeprecationException:
        DEPRECATION WARNING: DistributorUserSource model aliases `source` and has a method called `source` defined. Starting in Rails 7.2 `client_customer_platform` will not be calling `source` anymore. You may want to additionally define `client_customer_platform` to preserve the current behavior. (called from create_distributor_source at /Users/mrudul/Projects/Giftcard/distributor-api/app/models/distributor_user.rb:326)
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:220:in `block in generate_alias_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:219:in `each'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:219:in `generate_alias_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:290:in `block (3 levels) in define_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:289:in `each'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:289:in `block (2 levels) in define_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:287:in `each'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:287:in `block in define_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/code_generator.rb:41:in `batch'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/attribute_methods.rb:286:in `define_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/attribute_methods.rb:133:in `block in define_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/mutex_m-0.2.0/lib/mutex_m.rb:77:in `synchronize'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/mutex_m-0.2.0/lib/mutex_m.rb:77:in `mu_synchronize'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/attribute_methods.rb:130:in `define_attribute_methods'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/core.rb:786:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/persistence.rb:1142:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/validations.rb:435:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/dirty.rb:366:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/attribute_methods/dirty.rb:197:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/timestamp.rb:101:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/associations.rb:338:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/autosave_association.rb:277:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/transactions.rb:380:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/touch_later.rb:50:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/ar_transaction_changes-1.1.9/lib/ar_transaction_changes.rb:49:in `init_internals'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/core.rb:450:in `initialize'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/inheritance.rb:76:in `new'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/inheritance.rb:76:in `new'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/reflection.rb:176:in `build_association'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/associations/association.rb:353:in `build_record'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/associations/collection_association.rb:119:in `build'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/associations/collection_proxy.rb:319:in `build'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/relation.rb:241:in `find_or_initialize_by'
      # ./app/models/distributor_user.rb:326:in `create_distributor_source'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:403:in `block in make_lambda'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:183:in `block (2 levels) in halting_and_conditional'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:707:in `block (2 levels) in default_terminator'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:706:in `catch'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:706:in `block in default_terminator'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:184:in `block in halting_and_conditional'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:598:in `block in invoke_before'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:598:in `each'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:598:in `invoke_before'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:109:in `run_callbacks'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/callbacks.rb:952:in `_run_validation_callbacks'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/validations/callbacks.rb:115:in `run_validations!'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activemodel-7.1.3/lib/active_model/validations.rb:366:in `valid?'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/validations.rb:72:in `valid?'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/validations.rb:88:in `perform_validations'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/validations.rb:55:in `save!'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/transactions.rb:313:in `block in save!'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/transactions.rb:365:in `block in with_transaction_returning_status'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/transaction.rb:535:in `block in within_new_transaction'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activesupport-7.1.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/transaction.rb:532:in `within_new_transaction'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:344:in `transaction'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/transactions.rb:361:in `with_transaction_returning_status'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/transactions.rb:313:in `save!'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/activerecord-7.1.3/lib/active_record/suppressor.rb:56:in `save!'
      # ./app/models/distributor_user.rb:177:in `get_user'
      # ./spec/models/distributor_user_spec.rb:15:in `block (4 levels) in <top (required)>'
      # /Users/mrudul/.rvm/gems/ruby-3.2.2/gems/webmock-3.19.1/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

When I comment the as_enum line the spec passed with no failures.

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

1 participant