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

Stack Level Too Deep on YAML Serialization #385

Closed
CodingAnarchy opened this issue Aug 25, 2017 · 5 comments
Closed

Stack Level Too Deep on YAML Serialization #385

CodingAnarchy opened this issue Aug 25, 2017 · 5 comments

Comments

@CodingAnarchy
Copy link

CodingAnarchy commented Aug 25, 2017

PaperTrail is serializing the uploaded file (using CarrierWave) to YAML when the record is updated and the result is an infinite loop. Specifically, fog-aws is causing a crash when it iterates through files:

alias_method :each_file_this_page, :each
        def each
          if !block_given?
            self
          else
            subset = dup.all

            subset.each_file_this_page {|f| yield f}
            while subset.is_truncated
              subset = subset.all(:marker => subset.last.key)
              subset.each_file_this_page {|f| yield f} <- infinite recursion is here
            end

            self
          end
        end

This recurses until Ruby crashes on the stack level too deep error.

If it matters, the Ruby version is 2.4.1. There should only be one image file associated with the model that Paper Trail is saving a version of.

fog-aws version: 1.4.0
paper_trail version: 7.1.0

@CodingAnarchy
Copy link
Author

I have a workaround for now with has_paper_trail skip: [:image], but the underlying issue should probably still be addressed.

@geemus
Copy link
Member

geemus commented Aug 28, 2017

Hmm. I don't think the YAML serialization should be particularly impactful. The point you call out for recursion is related to reading back files from s3, rather than uploading them, which also makes me less sure about how this interaction is happening. Does the paper_trail call you make there just NOT upload the image? Sorry I'm not able to be more directly helpful, but it may make more sense for you to ask on the papertrail repo as it's not clear to me this is a bug in fog. Does that make sense?

@tomgi
Copy link

tomgi commented Aug 30, 2017

I have encountered the same problem.
It seems to be connected with using config.cache_storage = :fog and paper_trail.
With local cache_storage it's working just fine.

This is the repeating part of the stack trace:

fog-aws (1.4.1) lib/fog/aws/models/storage/files.rb:49:in `block in each'
fog-core (1.45.0) lib/fog/core/collection.rb:18:in `each'
fog-core (1.45.0) lib/fog/core/collection.rb:18:in `each'
fog-aws (1.4.1) lib/fog/aws/models/storage/files.rb:49:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:465:in `visit_array_subclass'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:410:in `visit_Array'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:593:in `block in dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:190:in `visit_Object'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:465:in `block in visit_array_subclass'
fog-aws (1.4.1) lib/fog/aws/models/storage/files.rb:49:in `block in each'
fog-core (1.45.0) lib/fog/core/collection.rb:18:in `each'
fog-core (1.45.0) lib/fog/core/collection.rb:18:in `each'
fog-aws (1.4.1) lib/fog/aws/models/storage/files.rb:49:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:465:in `visit_array_subclass'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:410:in `visit_Array'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:593:in `block in dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:190:in `visit_Object'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:593:in `block in dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:190:in `visit_Object'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:593:in `block in dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:591:in `dump_ivars'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:190:in `visit_Object'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:407:in `block in visit_Array'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:407:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:407:in `visit_Array'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:385:in `block in visit_Hash'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:383:in `each'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:383:in `visit_Hash'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:127:in `push'
~/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/psych.rb:416:in `dump'
paper_trail (7.1.1) lib/paper_trail/serializers/yaml.rb:14:in `dump'
paper_trail (7.1.1) lib/paper_trail/record_trail.rb:328:in `recordable_object_changes'
paper_trail (7.1.1) lib/paper_trail/record_trail.rb:228:in `data_for_create'
paper_trail (7.1.1) lib/paper_trail/record_trail.rb:210:in `record_create'
paper_trail (7.1.1) lib/paper_trail/model_config.rb:35:in `block in on_create'

@tomgi
Copy link

tomgi commented Aug 31, 2017

It seems to be connected with this issue - paper-trail-gem/paper_trail#134
paper_trail tries to serialize the whole model to yaml including the underlying uploader with AWS connection, etc.
It's working with local cache_storage however so I don't really know in which gem this issue should be posted.

@geemus
Copy link
Member

geemus commented Sep 8, 2017

Thanks for the additional detail. It sounds more like an issue with how paper_trail tries to serialize the uploader than an issue with the uploader itself. As such, it would probably make sense to report it over there instead. That said, in the linked issue it suggests a :skip option that might be helpful? ie maybe you can skip the uploader in the serialization and be good-to-go? In any event, I'm afraid it sounds more like a paperclip issue than fog. So I'm happy to discuss further, but my advise is likely to become pretty speculative.

@geemus geemus closed this as completed Sep 8, 2017
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

3 participants