rubysherpas / paranoia

acts_as_paranoid for Rails 5, 6 and 7
Other
2.87k stars 524 forks source link

acts_as_paranoid called more than once when using format validation #540

Closed besquared closed 10 months ago

besquared commented 1 year ago

This may be a problem in Rails 7.1 since I am using 7.1.0.alpha but may come up in the future.

If I include both acts_as_paranoid and validates :a, format: { ... } then acts_as_paranoid is loaded more than once. None of the other common validations seem to cause this. Console output, model file, and gem file included below.

irb(main):001:0> FilePath.c[WARN] FilePath is calling acts_as_paranoid more than once!
irb(main):001:0> FilePath.cr[WARN] FilePath is calling acts_as_paranoid more than once!
irb(main):001:0> FilePath.cre[WARN] FilePath is calling acts_as_paranoid more than once!
irb(main):001:0> FilePath.crea[WARN] FilePath is calling acts_as_paranoid more than once!
class FilePath < ApplicationRecord
  acts_as_paranoid

  # Validations

  validates :name, format: {
      with: /^[a-zA-Z0-9_\-\s\.]+$/,
      message: "Invalid file name"
    }
end
# frozen_string_literal: true

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

ruby '3.2.2'

gem 'dotenv-rails'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
# gem "rails", "~> 7.1.0.alpha"
gem 'rails', github: 'rails/rails', branch: 'main'

gem 'pg', '~> 1.4'

# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'

# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '>= 5.0'

gem 'propshaft'
gem 'importmap-rails'
gem 'jsbundling-rails'
gem 'cssbundling-rails'

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem 'turbo-rails'

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem 'stimulus-rails'

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'

# Use Redis adapter to run Action Cable in production
gem "redis", ">= 4.0.1"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
gem "kredis"

gem 'sidekiq'

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[windows jruby]

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem 'httparty'

gem 'aasm'
gem 'ancestry'
gem 'paranoia'
gem 'acts_as_list'
gem 'image_processing'

# Use OmniAuth to support multi-provider authentication [https://github.com/omniauth/omniauth]
gem "omniauth"
# Provides a mitigation against CVE-2015-9284 [https://github.com/cookpad/omniauth-rails_csrf_protection]
gem "omniauth-rails_csrf_protection"
# Use rotp for generating and validating one time passwords [https://github.com/mdp/rotp]
gem "rotp"
# Use rqrcode for creating and rendering QR codes into various formats [https://github.com/whomwah/rqrcode]
gem "rqrcode"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
gem "bcrypt", "~> 3.1.7"
# Use Rack::Ratelimit to rate limit requests [https://github.com/jeremy/rack-ratelimit]
gem "rack-ratelimit", group: :production

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem 'web-console'

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"

  gem 'error_highlight', '>= 0.4.0', platforms: [:ruby]

  gem 'rubocop'

  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

  gem "authentication-zero", "~> 2.16"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem 'capybara'
  gem 'factory_bot_rails', '~> 6.2'
  gem 'rspec-rails'
  gem 'selenium-webdriver'
  gem 'webdrivers'
  gem 'faker'
end
mathieujobin commented 1 year ago

Thank you for opening this. I am in the process of upgrading my app to 7.1-alpha, but I have not encountered this problem specifically yet...

please do let us know if you find out more..

mathieujobin commented 10 months ago

it appears you experienced this problem in the recent debug gem session? does it happens in production? did it cause any actual problems? I have a feeling it could be related to the debugger reloading code. especially in dev environment.

please reopen if you find more information on how to reproduce. etc.

PRs are very welcome