0

We are working on updating the ruby version from 2.3.1 to 3.0.2 and related changes. We are facing an issue while uploading a file. I have just set the form of file upload and set upload event without any model connection for testing. Event model has not created or attached any file, on submit button, system raises TypeError.

I have changed dalli cache store to mem_cache_store as part of updating ruby and rails "config.cache_store = :mem_cached_store"

I have checked the cache.rb and issue raise in compress! method when "serialized = Marshal.dump(@value)"

Also set param[:image] = nil rescue nil, so it's clear before redirect but still in session I found image file upload entry. Is this error due to Marshal.dump trying to serialize file upload objects?

Is there any way to solve this error?

Error:

TypeError: can't dump File
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:858:in `dump'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:858:in `compress!'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:792:in `initialize'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:475:in `new'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:475:in `block in write'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:726:in `block in instrument'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/notifications.rb:205:in `instrument'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:726:in `instrument'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache.rb:474:in `write'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/session/cache_store.rb:34:in `write_session'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:388:in `commit_session'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:268:in `context'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/cookies.rb:689:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/web-console-2.3.0/lib/web_console/middleware.rb:28:in `block in call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
from /home/test/.rvm/gems/ruby-3.0.2/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/railties-6.1.4.1/lib/rails/rack/logger.rb:37:in `call_app'
from /home/test/.rvm/gems/ruby-3.0.2/gems/railties-6.1.4.1/lib/rails/rack/logger.rb:26:in `block in call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/tagged_logging.rb:101:in `block in tagged'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/tagged_logging.rb:37:in `tagged'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/tagged_logging.rb:101:in `tagged'
from /home/test/.rvm/gems/ruby-3.0.2/gems/railties-6.1.4.1/lib/rails/rack/logger.rb:26:in `call'
from /media/test/DATA1/user/sampleproject/lib/custom_logger.rb:17:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/request_store-1.5.0/lib/request_store/middleware.rb:19:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/request_id.rb:26:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/activesupport-6.1.4.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/static.rb:24:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/actionpack-6.1.4.1/lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-mini-profiler-2.3.3/lib/mini_profiler/profiler.rb:393:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/railties-6.1.4.1/lib/rails/engine.rb:539:in `call'
from /home/test/.rvm/gems/ruby-3.0.2/gems/railties-6.1.4.1/lib/rails/railtie.rb:207:in `public_send'
from /home/test/.rvm/gems/ruby-3.0.2/gems/railties-6.1.4.1/lib/rails/railtie.rb:207:in `method_missing'
from /home/test/.rvm/gems/ruby-3.0.2/gems/rack-2.2.3/lib/rack/handler/webrick.rb:95:in `service'
from /home/test/.rvm/gems/ruby-3.0.2/gems/webrick-1.7.0/lib/webrick/httpserver.rb:140:in `service'
from /home/test/.rvm/gems/ruby-3.0.2/gems/webrick-1.7.0/lib/webrick/httpserver.rb:96:in `run'
from /home/test/.rvm/gems/ruby-3.0.2/gems/webrick-1.7.0/lib/webrick/server.rb:310:in `block in start_thread

sample test file:

<%= form_with :url => uploads_project_path(@project), :method => :post, multipart: true, :remote => true do |f| %>
  <div>
    <%= f.label :title %>
    <%= f.text_field :title %>
  </div>
  <div>
    <%= f.label :image %>
    <%= f.file_field :image %>
  </div>
  <%= f.submit %>
<% end %>
Chandan
  • 11,465
  • 1
  • 6
  • 25
  • You should consider updating to `2.7.4` first instead of jumping straight to Ruby 3. There are a few breaking changes (most notably connected to keywords) and 2.7.4 will give depreachiation notices. – max Sep 20 '21 at 19:05
  • `rescue nil` is also an anti-pattern know as Pokemón exception handling which creates a black hole that swallows **any** type of exception and makes debugging a nightmare. Only rescue specific exceptions classes that you know what to do with. Use the safe navigation operator instead if you're trying to avoid a nil error. – max Sep 20 '21 at 19:08
  • Thanks @max , i have check with Ruby 2.5.0 with Rails 5.1.4 version still same error comes, i think some issue with fileupload objects tempfile. if i removed temp file "params[:image].tempfile = nil" then marshal.dump not gives any error so my guess it's due to attachment file. but params[:image].tempfile is original attachment and can't remove it due to further process. Might be mem_cache_stored ? don't know. for not not getting any clues. – mohit chavda Sep 22 '21 at 07:12

0 Answers0