Skip to content

Commit

Permalink
Duplicate #892 - Rails 6 save stack too deep on File upload (#899)
Browse files Browse the repository at this point in the history
* fix rails 6 save loop callback stack

* update to support backward compatibility

* use proc

* add same change to fragment

* code review

* Upgrading sqlite3 to 1.4
  • Loading branch information
nitsujri authored and GBH committed Dec 9, 2019
1 parent b85e105 commit e13ce5d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ group :development, :test do
gem "puma", "~> 3.11.2"
gem "rubocop", "~> 0.55.0", require: false
gem "selenium-webdriver", "~> 3.9.0"
gem "sqlite3", "~> 1.3.13"
gem "sqlite3", "~> 1.4"
end

group :development do
Expand Down
7 changes: 6 additions & 1 deletion app/models/comfy/cms/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class Comfy::Cms::File < ActiveRecord::Base
# -- Callbacks ---------------------------------------------------------------
before_validation :assign_label, on: :create
before_create :assign_position
after_save :process_attachment
# active_storage attachment behavior changed in rails 6 - see PR#892 for details
if Rails::VERSION::MAJOR >= 6
before_save :process_attachment
else
after_save :process_attachment
end

# -- Validations -------------------------------------------------------------
validates :label, presence: true
Expand Down
8 changes: 6 additions & 2 deletions app/models/comfy/cms/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class Comfy::Cms::Fragment < ActiveRecord::Base
attr_reader :files

# -- Callbacks ---------------------------------------------------------------
after_save :remove_attachments,
:add_attachments
# active_storage attachment behavior changed in rails 6 - see PR#892 for details
if Rails::VERSION::MAJOR >= 6
before_save :remove_attachments, :add_attachments
else
after_save :remove_attachments, :add_attachments
end

# -- Relationships -----------------------------------------------------------
belongs_to :record, polymorphic: true, touch: true
Expand Down
2 changes: 1 addition & 1 deletion test/gemfiles/5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ group :development, :test do
gem "puma", "~> 3.11.2"
gem "rubocop", "~> 0.55.0", require: false
gem "selenium-webdriver", "~> 3.9.0"
gem "sqlite3", "~> 1.3.13"
gem "sqlite3", "~> 1.4"
end

group :test do
Expand Down

0 comments on commit e13ce5d

Please sign in to comment.