# Problem with ActiveRecord and PDFWriter

**URL:** <https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241>\
**Category:** Ruby\
**Created:** [December 4, 2006, 12:49pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241 "2006-12-04T12:49:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 4, 2006, 12:49pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/1 "2006-12-04T12:49:01Z")

</div>

Probably this has been discussed earlier elsewhere.

I am having some problem while using PDFWriter in rails. following  
code throws error:

my\_table.render\_on(pdf)

In short, I get error:

no marshal\_dump is defined for class Mutex

RAILS\_ROOT: /home/hemant/foo\_app/config/…  
Application Trace | Framework Trace | Full Trace

/usr/local/lib/site\_ruby/1.8/transaction/simple.rb:370:in `dump' /usr/local/lib/site_ruby/1.8/transaction/simple.rb:370:in `start\_transaction’  
/usr/local/lib/site\_ruby/1.8/transaction/simple/group.rb:89:in  
`start_transaction' /usr/local/lib/site_ruby/1.8/transaction/simple/group.rb:89:in `start\_transaction’  
/usr/local/lib/site\_ruby/1.8/pdf/simpletable.rb:397:in `render_on' #{RAILS_ROOT}/app/controllers/analytics_controller.rb:266:in `pdf\_download’  
#{RAILS\_ROOT}/app/controllers/analytics\_controller.rb:224:in  
`pdf\_download’  
/usr/bin/mongrel\_rails:18

It turns out that, people in past also had problems when using  
PDFWriter under rails, because rails bundles its own version of  
Simple Transaction(simple.rb) package.

But the package bundled with rails is not complete and hence the  
libraries that need full blown simple transaction package more or less  
break.

I have also tried patching activerecord with this patch:

[http://dev.rubyonrails.org/attachment/ticket/4732/do-not-require-transaction-simple-if-already-loaded.patch](http://dev.rubyonrails.org/attachment/ticket/4732/do-not-require-transaction-simple-if-already-loaded.patch)

doesn’t seem to work. I am also using LoginEngine _code_ (i.e just the  
code, not the engine itself ,for admin interface). But I have got rid  
of most of the transaction statements from the code for the time  
being.

So, I am curious…

1. If the problem is in my code?
2. If there is a problem with PDFWriter or AR
3. Or the said patch simply doesn’t work

What are my options?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 4, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/2 "2006-12-04T14:17:13Z")

</div>

On 12/4/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> no marshal\_dump is defined for class Mutex

You look like you’re doing something threaded. I don’t know if that’s  
Rails doing it for you, but you can’t dump either threads or mutexes  
in Ruby. You _must_ have the latest Transaction::Simple (and Rails  
_really_ needs to remove it and add the latest version as a  
dependency; I’m getting ready to release a new version that’s even  
more useful and PDF::Writer _will_ depend on it moving forward).

> 1. If the problem is in my code?
> 2. If there is a problem with PDFWriter or AR
> 3. Or the said patch simply doesn’t work

I suspect 1, 2 (with respect to ActiveRecord bundling  
Transaction::Simple; something I’ve asked them to fix a long time  
ago), and 3.

-austin

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/3 "2006-12-11T14:45:33Z")

</div>

Austin Z. a écrit :

> > 1. If the problem is in my code?
> > 2. If there is a problem with PDFWriter or AR
> > 3. Or the said patch simply doesn’t work
> 
> I suspect 1, 2 (with respect to ActiveRecord bundling  
> Transaction::Simple; something I’ve asked them to fix a long time  
> ago), and 3.
> 
> -austin

Hello,

I have exactly the same problem. But the problem doesn’t appear if I  
test in local with webrick (in development or production environment)  
but it appears with apache+mongrel.

All the libraries are in the same version on both configuration (1.1.6  
for rails, 1.3.0 for transaction-simple and 1.1.3 for pdf-writer).

I really don’t know what to do.  
Any help ?

Thanks in advance.  
++ Jerome

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/4 "2006-12-11T18:49:16Z")

</div>

On 12/11/06, Jérôme Loyet [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > dependency; I’m getting ready to release a new version that’s even  
> > -austin  
> > I really don’t know what to do.  
> > Any help ?

I have tried in vain to patch AR, but it doesn’t seem to ( sorry for  
violating DRY)  
Hmm…there are couple of things which are threaded in my app, but  
they don’t run within rails. For example:

1. Mongrel itself is threaded.
2. Backgroundrb I am using, which is threaded.
3. I am using a third party charting thingy, which is threaded.

But when I went through code of PDFWriter, it seemed that indeed they  
create a mutex and start the transaction. Now, there ain’t any mutexes  
anywhere in my code and the library I am using is well tucked away. So  
only guy creating a mutex was PDFWriter and i suspect PDFWriter is  
only trying to dump it.

I am really out of ideas, here… if anyone can help?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/5 "2006-12-11T21:15:41Z")

</div>

On 12/12/06, Austin Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Good point Austin, and honestly I was populating some PDF variables  
from session, But then I removed those lines from code and still the  
error.

If you don’t mind can I send you the code offlist and If you can have a  
look?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/6 "2006-12-11T20:39:33Z")

</div>

On 12/11/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But when I went through code of PDFWriter, it seemed that indeed they  
> create a mutex and start the transaction. Now, there ain’t any mutexes  
> anywhere in my code and the library I am using is well tucked away. So  
> only guy creating a mutex was PDFWriter and i suspect PDFWriter is  
> only trying to dump it.

Trust me. PDF::Writer isn’t trying to dump a mutex here (this is  
something I know well). Have you put a PDF variable in a session or  
something like that?

-austin

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/7 "2006-12-11T21:31:44Z")

</div>

On 12/11/06, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > something like that?  
> > Good point Austin, and honestly I was populating some PDF variables  
> > from session, But then I removed those lines from code and still the  
> > error.
> 
> If you don’t mind can I send you the code offlist and If you can have a look?

Sure. Don’t expect a quick response, though. I’ve written one Rails  
application.

-austin

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 10:23pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/8 "2006-12-11T22:23:57Z")

</div>

> Transaction::Simple; something I’ve asked them to fix a long time  
> ago), and 3.

You could probably distribute a Rails plugin with PDF::Writer as a  
workaround. Unless upgrading Transaction::Simple breaks Rails?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [December 11, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/problem-with-activerecord-and-pdfwriter/78241/9 "2006-12-11T22:36:03Z")

</div>

On 12/11/06, Giles B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Transaction::Simple; something I’ve asked them to fix a long time  
> > ago), and 3.
> 
> You could probably distribute a Rails plugin with PDF::Writer as a  
> workaround. Unless upgrading Transaction::Simple breaks Rails?

I will not be doing so. I provide a _Ruby_ library. I have told the  
Rails folks that they should be using Transaction::Simple library as a  
gem, because I guarantee compatibility.

-austin
