wicked_pdf icon indicating copy to clipboard operation
wicked_pdf copied to clipboard

Adding wicked_pdf leads to fatal error on any render

Open Zeouterlimits opened this issue 5 years ago • 11 comments

Issue description

Added wicked_pdf + wkhtmltopdf-binary to gemfile of existing spa project Generated wicked initializer with default config Startup application Try to render any page (not ones that are invoking wicked pdf):

[a7a7e671-2c8c-4e2a-8274-aadef48292b2]
[a7a7e671-2c8c-4e2a-8274-aadef48292b2] FrozenError (can't modify frozen fatal):
[a7a7e671-2c8c-4e2a-8274-aadef48292b2]

Expected or desired behavior

No error occuring?

System specifications

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf):

cat Gemfile.lock | grep wicked_pdf
    wicked_pdf (1.4.0)
  wicked_pdf

wkhtmltopdf version (output of wkhtmltopdf --version):

bundle exec wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

whtmltopdf provider gem and version if one is used:

cat Gemfile.lock | grep wkhtmltopdf
    wkhtmltopdf-binary (0.12.5)
  wkhtmltopdf-binary

platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar): Mac OS X Mojave 10.14.6

Zeouterlimits avatar Jan 02 '20 02:01 Zeouterlimits

When you say this is an SPA, do you mean that this is Rails running in API mode (no view rendering). If so, this thread has some tips for that.

What version of Ruby and Rails are you running?

unixmonkey avatar Jan 02 '20 14:01 unixmonkey

No, it does have simplistic view rendering, in which we wrap react pages.

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
bundle exec rails -v
Rails 6.0.0

Zeouterlimits avatar Jan 03 '20 01:01 Zeouterlimits

Can you try and point your Gemfile at the master branch and see if that helps? I very recently merged a Rails 6 comparatively PR, but haven’t released it yet.

unixmonkey avatar Jan 03 '20 04:01 unixmonkey

Gave it a go, unfortunately I get the same fatal FrozenError. Tried to increase my log level to debug but no futher info exposed.

While trying to research it, I did find someone else had this issue with the gem: https://stackoverflow.com/questions/55301110/frozen-error-when-trying-to-run-rails-application

Perhaps a deprecation error failing somewhat silently: https://github.com/rails/rails/pull/37088 (not released yet I think)

Zeouterlimits avatar Jan 03 '20 05:01 Zeouterlimits

Thanks for that extra context. The comment that this is being raised as the result of a SystemStackError seems like a decent explanation. This gem has some incompatibilities with other gems that try to do similar thing by either prepending or alias_method_chaining of render. I intend to allow you to disable this behavior eventually.

Here are some threads that may help you determine what gem could be interfering, and some tips to work around this: https://github.com/mileszs/wicked_pdf/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+SystemStackError

Let me know how it goes. If you keep having trouble, I'm sure I can help you out (probably with a monkeypatch or something), just let me know.

unixmonkey avatar Jan 03 '20 19:01 unixmonkey

@unixmonkey I am also having this same issue. On my machine I get a FrozenError: can't modify frozen fatal and my teammate is getting an interpreter crash. We noticed that the issue happened when ActiveSupport.on_load was introduced and were able to work around this by monkey patching wicked_pdf railtie, completely removing that code, and manually including the helpers in controllers and view helpers where needed. Specifically, I think ActionController::Base.send :prepend, PdfHelper is causing it for us because removing that line makes it so that FrozenError is not thrown. Any idea as to what's going on?

summera avatar Jan 17 '20 21:01 summera

I had the same when including gem 'wicked_pdf' to my Rails 5 application. It seems the latest version of Wicked PDF depends on Rails 6, could this be a similar problem?

bo-oz avatar Feb 24 '20 15:02 bo-oz

@bo-oz I don't think Rails 5 compatibility has anything to do with your issue. I've tested with Rails 5 and the current version. I have seen incompatibility with other gems that also override render, like the "remotipart" gem.

If this is your issue, there are some suggestions in #650 that may help you track it down.

unixmonkey avatar Feb 24 '20 16:02 unixmonkey

Hi Guys, any update on this?

gerardo-navarro avatar Jul 15 '20 04:07 gerardo-navarro

same for us 🤷🏿

it's because we override def render of application controller

# def render(*args)
 #   response.set_header('Original-User', User.find(session[:original_user_id]).name) if session[:original_user_id]
 #   super
 # end

if i comment it, it works. if i use my override, it's an infinity loop

krtschmr avatar Apr 07 '21 11:04 krtschmr

Hi there, I was facing this exact same problem on version 1.4.0. Upgrading to 2.6.3 solved the problem for me.

I've found out that when overriding the render method caused WickedPdf::PdfHelper to loop back to itself on this file lib/wicked_pdf/pdf_helper.rb:46

method(:render).super_method.call(options, *args, &block)

Anyway, here we are using Rails 6.1 with Ruby 2.7

wgirhad avatar Apr 04 '23 16:04 wgirhad