-
Notifications
You must be signed in to change notification settings - Fork 638
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
Fix rails 6 save loop callback stack too deep on File upload in admin #892
base: master
Are you sure you want to change the base?
Conversation
That's a little strange imho: if you save the attachment before the comfy File model, the attachment shouldn't be able to attach itself to anything (as the File model doesn't have an id yet). |
Totally agree it's strange - I'm used to funny callback chaining behavior problem cases but I've never seen behavior changes in rails version changes like this. The behavior of active storage
lines up with the behavior I'm seeing - looks like if |
In fact, Rails 6's behaviour is better imho, but your PR also changed how the attachment save code behaves on 5.2... What do you think about conditionally adapting the hook for Rails <6, >=6? |
Happy to add backwards compatibility - just pushed a commit for that. I didn't see any existing standards to use as far as styling/methodology for version checking, please let me know if you'd like me to make any adjustments to how I did it. |
@tongboy Thanks for this fix! This needs to be applied to Comfy::Cms::Fragment as well. |
@morgant PR updated! |
Hi guys, any thoughts on how to get the test/test-migration to pass? Really looking forward to this PR merged in! |
The test failures all appear to be a gem issue, maybe it just needs to be rebased? |
PR #899, which was a duplicate of this, has been merged, so this can probably be closed. |
I don't believe this is actually fixed, at least for a record that is being updated. The Since it is a def process_attachment
return if @file.blank?
self.attachment = @file
end |
I can confirm it's not fixed for updating, which can be verified with export/import of seeds |
…a into bichinger * 'master' of github.com:bichinger/comfortable-mexican-sofa: fix seeds exporter (comfy#911) Bump comfortable_mexican_sofa to 2.0.19 fixing issue with rack 2.0.8 will this works with sprokets 4? syncing locale files feat(I18n): added arabic locale (comfy#897) bumping puma bumping sqlite gem rails 6 needs ruby 2.5+ wip getting things not crash in for rails 6 Duplicate comfy#892 - Rails 6 save stack too deep on File upload (comfy#899) bug with when there are no pages updating test matrix # Conflicts: # Gemfile
Summary
When CMS is included in a rails 6 parent app the after_save callback on the file model causes an endless callback loop that runs until a stack level too deep error is returned. And the file is not successfully uploaded/saved.
I reviewed the change logs for active storage and didn't see anything that seemed relevant. I suspect there is a change in the behavior in there somewhere and I just failed to find it.
Moving the callback to a
before_save
resolves the issue. tests continue to pass on 5.2 with the change.the repeating stack is:
Please let me know if I can add any further tests or anything else. Thanks for the great gem!