Navigation Menu

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

Bogus deprecation warning on find_or_create_by #38303

Closed
ojab opened this issue Jan 24, 2020 · 2 comments
Closed

Bogus deprecation warning on find_or_create_by #38303

ojab opened this issue Jan 24, 2020 · 2 comments

Comments

@ojab
Copy link
Contributor

ojab commented Jan 24, 2020

Steps to reproduce

AFAIU unscoped behaviour will be default one in 6.1, but right now there is no way to force it, so deprecation warning is essentially unfixable.
See brendon/acts_as_list#363 for example.

# 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", github: "rails/rails"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"
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|
    t.text :text
  end
end

class Post < ActiveRecord::Base
  after_save :acts_as_list

  def acts_as_list
    Post.unscope(:where)
  end
end

ActiveSupport::Deprecation.behavior = :raise

class BugTest < Minitest::Test
  def test_association_stuff
    Post.find_or_create_by!(text: 'text')
  end
end

Expected behavior

No deprecation warning

Actual behavior

ActiveSupport::DeprecationException: DEPRECATION WARNING: Class level methods will no longer inherit scoping from create!in Rails 6.1. To continue using the scoped relation, pass it into the block directly. To instead access the full set of models, as Rails 6.1 will, usePost.unscoped, or Post.default_scoped if a model has default scopes. (called from acts_as_list at active_record_master.rb:32)

System configuration

Rails version: 6.0 or git master

Ruby version: 2.6.5

@ojab
Copy link
Contributor Author

ojab commented Jan 24, 2020

Maybe we can do if scope.present? here, but I'm not sure if it's a correct fix.

@kamipo
Copy link
Member

kamipo commented Jan 27, 2020

Related #38241.

Use default_scoped in this case for 6.1 migration to avoid leaking scope. #38319

@kamipo kamipo closed this as completed Jan 27, 2020
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

2 participants