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

TypeError (no implicit conversion to float from string) on Ubuntu #236

Closed
belangp opened this issue May 31, 2020 · 9 comments
Closed

TypeError (no implicit conversion to float from string) on Ubuntu #236

belangp opened this issue May 31, 2020 · 9 comments
Labels

Comments

@belangp
Copy link

belangp commented May 31, 2020

Hi all,

I've updated my gems to their latest version and updated libvips to 8.10.0. Everything works perfectly well on MacOS, however, on Ubuntu, I'm getting the following message:

TypeError (no implicit conversion to float from string):
  
ruby-vips (2.0.17) lib/vips/gvalue.rb:106:in `g_value_set_double'
ruby-vips (2.0.17) lib/vips/gvalue.rb:106:in `set'
ruby-vips (2.0.17) lib/vips/object.rb:258:in `set'
ruby-vips (2.0.17) lib/vips/operation.rb:249:in `set'
ruby-vips (2.0.17) lib/vips/operation.rb:384:in `block in call'
ruby-vips (2.0.17) lib/vips/operation.rb:377:in `each_index'
ruby-vips (2.0.17) lib/vips/operation.rb:377:in `call'
ruby-vips (2.0.17) lib/vips/image.rb:211:in `method_missing'
image_processing (1.11.0) lib/image_processing/processor.rb:62:in `public_send'
image_processing (1.11.0) lib/image_processing/processor.rb:62:in `apply_operation'
image_processing (1.11.0) lib/image_processing/processor.rb:39:in `apply_operation'
image_processing (1.11.0) lib/image_processing/processor.rb:19:in `block in call'
image_processing (1.11.0) lib/image_processing/processor.rb:18:in `each'
image_processing (1.11.0) lib/image_processing/processor.rb:18:in `call'
image_processing (1.11.0) lib/image_processing/pipeline.rb:50:in `call_processor'
image_processing (1.11.0) lib/image_processing/pipeline.rb:28:in `block in call'
image_processing (1.11.0) lib/image_processing/pipeline.rb:64:in `create_tempfile'
image_processing (1.11.0) lib/image_processing/pipeline.rb:27:in `call'
image_processing (1.11.0) lib/image_processing/builder.rb:13:in `call!'
image_processing (1.11.0) lib/image_processing/chainable.rb:65:in `call'
activestorage (6.0.3.1) lib/active_storage/transformers/image_processing_transformer.rb:15:in `process'
activestorage (6.0.3.1) lib/active_storage/transformers/transformer.rb:25:in `transform'
activestorage (6.0.3.1) app/models/active_storage/variation.rb:52:in `block in transform'
activesupport (6.0.3.1) lib/active_support/notifications.rb:182:in `instrument'
activestorage (6.0.3.1) app/models/active_storage/variation.rb:51:in `transform'
activestorage (6.0.3.1) app/models/active_storage/variant.rb:105:in `transform'
activestorage (6.0.3.1) app/models/active_storage/variant.rb:100:in `block in process'
activestorage (6.0.3.1) lib/active_storage/downloader.rb:15:in `block in open'
activestorage (6.0.3.1) lib/active_storage/downloader.rb:24:in `open_tempfile'
activestorage (6.0.3.1) lib/active_storage/downloader.rb:12:in `open'
activestorage (6.0.3.1) lib/active_storage/service.rb:86:in `open'
activestorage (6.0.3.1) app/models/active_storage/blob.rb:219:in `open'
activestorage (6.0.3.1) app/models/active_storage/variant.rb:99:in `process'
activestorage (6.0.3.1) app/models/active_storage/variant.rb:67:in `processed'
activestorage (6.0.3.1) app/controllers/active_storage/representations_controller.rb:12:in `show'
actionpack (6.0.3.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.1) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.3.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.3.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.3.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.3.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.3.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.3.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.3.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.3.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.3.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.0.3.1) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:834:in `call'
http_accept_language (2.1.1) lib/http_accept_language/middleware.rb:14:in `call'
rack (2.2.2) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.2) lib/rack/etag.rb:27:in `call'
rack (2.2.2) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.2) lib/rack/head.rb:12:in `call'
actionpack (6.0.3.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.2) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.2) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.3.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.3.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.1) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.1) lib/rails/rack/logger.rb:26:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.2) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/ssl.rb:74:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/host_authorization.rb:76:in `call'
railties (6.0.3.1) lib/rails/engine.rb:527:in `call'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'

I followed all installation instructions, set the variables in .bashrc and .bash_profile as requested for libvips and ruby-vips:

.bashrc file:

export VIPSHOME=/usr/local
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$VIPSHOME/lib
export PATH=$PATH:$VIPSHOME/bin
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$VIPSHOME/lib/pkgconfig
export MANPATH=$MANPATH:$VIPSHOME/man
export PYTHONPATH=$VIPSHOME/lib/python2.7/site-packages

.bash_profile file:

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

.profile file:

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
rails@ip-172-31-79-166:~$ cat .profile

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11/lib/pkgconfig

Using Rails with RVM 1.29.10 and Ruby 2.6.5 on all my systems.

Any suggestions as to why it won't work on Ubuntu, but works on MacOS?

@jcupitt
Copy link
Member

jcupitt commented May 31, 2020

Hi @belangp,

image_processing (1.11.0) lib/image_processing/processor.rb:62:in `public_send'

It looks like image_processing is passing a string where ruby-vips is expecting a float. But that's all I can tell from your backtrace. We need to know what operation IP is calling and what parameters it is passing.

ruby-vips has debug logging. Try:

require 'vips'
GLib::logger.level = Logger::DEBUG

Though it's incredibly chatty. You could try enabling that and see if there's any useful output before the error.

@belangp
Copy link
Author

belangp commented May 31, 2020

Thanks @jcupitt , the logger output is:

D, [2020-05-31T12:11:38.977708 #2952] DEBUG -- Vips::VipsOperation.call: name = VipsForeignLoadPngFile, supplied = ["/tmp/ActiveStorage-4-20200531-2952-6rkqzw.png"], optional = {}, option_string = 
D, [2020-05-31T12:11:38.977895 #2952] DEBUG -- Vips::Object.set: filename = /tmp/ActiveStorage-4-20200531-2952-6rkqzw.png
D, [2020-05-31T12:11:38.978350 #2952] DEBUG -- Vips::Object.get: out == #<Vips::Image:0x00005646f13e6398>
D, [2020-05-31T12:11:38.978389 #2952] DEBUG -- Vips::Operation.call: result = #<Vips::Image:0x00005646f13e6398>
D, [2020-05-31T12:11:38.978695 #2952] DEBUG -- Vips::VipsOperation.call: name = autorot, supplied = [#<Image 3099x1819 uchar, 4 bands, srgb>], optional = {}, option_string = 
D, [2020-05-31T12:11:38.978826 #2952] DEBUG -- Vips::Object.set: in = #<Vips::Image:0x00005646f13e6398>
D, [2020-05-31T12:11:38.979128 #2952] DEBUG -- Vips::Object.get: out == #<Vips::Image:0x00005646f13e9d18>
D, [2020-05-31T12:11:38.979160 #2952] DEBUG -- Vips::Operation.call: result = #<Vips::Image:0x00005646f13e9d18>
D, [2020-05-31T12:11:38.979441 #2952] DEBUG -- Vips::VipsOperation.call: name = resize, supplied = [#<Image 3099x1819 uchar, 4 bands, srgb>, "150x150>"], optional = {}, option_string = 
D, [2020-05-31T12:11:38.979581 #2952] DEBUG -- Vips::Object.set: in = #<Vips::Image:0x00005646f13e9d18>
D, [2020-05-31T12:11:38.979661 #2952] DEBUG -- Vips::Object.set: scale = 150x150>

@jcupitt
Copy link
Member

jcupitt commented May 31, 2020

Yes, the call to resize is wrong. It expects a single float number (the scale factor), but someone is passing the string "150x150>". You'll need to track down where that's coming from.

@belangp
Copy link
Author

belangp commented May 31, 2020

Found it! Thanks a lot for your help and quick responses, really appreciate it!

@belangp belangp closed this as completed May 31, 2020
@jcupitt
Copy link
Member

jcupitt commented May 31, 2020

No problem.

I'd avoid resize (in case it was your code triggering that). It's /much/ faster to use thumbnail instead (perhaps 4x faster), and quality is better too.

@belangp
Copy link
Author

belangp commented May 31, 2020

For others struggling with this issue, ActiveStorage switched from using MiniMagick to using image_processing.

If you used to do something like this:
image.variant(resize: "150x150>")

the new correct way is to use:
image.variant(resize_to_fill: [150, nil])

Refer to this page for details on the options available:

@belangp
Copy link
Author

belangp commented May 31, 2020

It was indeed in my code. Thanks for the tip @jcupitt I'll look into this for sure! :)

@jcupitt
Copy link
Member

jcupitt commented May 31, 2020

I think if you're using resize_to_fill you should be OK. It'll call thumbnail for you behind the scenes.

You can verify by enabling logging and looking at the sequence of calls image_processing is making.

You can also set the VIPS_TRACE env var and you'll see output like:

$ VIPS_TRACE=1 vipsthumbnail k2.jpg
vips cache+: jpegload filename="k2.jpg" out=((VipsImage*) 0x558a01c571b0) flags=((VipsForeignFlags) VIPS_FOREIGN_SEQUENTIAL) -
vips cache : jpegload filename="k2.jpg" out=((VipsImage*) 0x558a01c57340) shrink=8 flags=((VipsForeignFlags) VIPS_FOREIGN_SEQUENTIAL) access=((VipsAccess) VIPS_ACCESS_SEQUENTIAL) -
vips cache+: colourspace in=((VipsImage*) 0x558a01c57340) out=((VipsImage*) 0x558a01c574d0) space=((VipsInterpretation) VIPS_INTERPRETATION_sRGB) -
vips cache : copy in=((VipsImage*) 0x558a01c574d0) out=((VipsImage*) 0x558a01c577f0) -
vips cache : copy in=((VipsImage*) 0x558a01c577f0) out=((VipsImage*) 0x558a01c57b10) -
vips cache+: embed in=((VipsImage*) 0x558a01c57b10) out=((VipsImage*) 0x558a01c57ca0) x=0 y=5 width=181 height=269 extend=((VipsExtend) VIPS_EXTEND_COPY) -
vips cache+: linecache in=((VipsImage*) 0x558a01c57e30) out=((VipsImage*) 0x558a01d00190) tile-height=10 access=((VipsAccess) VIPS_ACCESS_SEQUENTIAL) persistent=TRUE -
vips cache+: sequential in=((VipsImage*) 0x558a01c57e30) out=((VipsImage*) 0x558a01d00000) tile-height=10 -
...

It's not quite as insanely chatty as ruby-vips logging.

@belangp
Copy link
Author

belangp commented May 31, 2020

I did check the image_storage documentation and that's correct. All resize_to_* will call thumbnail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants