[Dancer-users] Plugin::Database failed on reconnect

David Precious davidp at preshweb.co.uk
Thu Apr 12 11:41:05 CEST 2012

On Thu, 12 Apr 2012 10:53:00 +0300
WK <wanradt at gmail.com> wrote:

> Hi!
> My little application stand whole night and when on morning user made
> first request, app did not connect properly to Database. Error was
> like:
> DBD::mysql::db do failed: You have an error in your SQL syntax; check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near
> '&amp;amp;amp;amp;amp;amp;amp;amp;amp;#39;utf8&amp;amp;amp;amp;amp;amp;amp;amp;am'
> at line 1 at /usr/local/share/perl/5.12.4/Dancer/Plugin/Database.pm
> line 198.
> /usr/local/share/perl/5.12.4/Dancer/Plugin/Database.pm around line 198
> 195         return;
> 196     } elsif (exists $settings->{on_connect_do}) {
> 197         for (@{ $settings->{on_connect_do} }) {
> 198             $dbh->do($_) or Dancer::Logger::error(
> 199                 "Failed to perform on-connect command $_"
> 200             );
> 201         }

Uh-oh - that's probably not good :)

Do you have any on_connect_do settings defined in your app's config?

> As i use also Plugin::EscapeHTML with automatic_escaping: 1,  it seems
> that there is some problem with 2 of them together. At least there is
> made some weird escaping. Or?

That would seem to be the likely culprit, but at a quick glance, I
don't see why that should be happening.

D::P::EscapeHTML's automatic escaping stuff is in a
before_template_render hook, and steps through the template params
passed to it.

Ah, wait.  I think that's it - Dancer::Template::Abstract shoves the
config information into the template tokens hashref:

148     $tokens->{settings}       = Dancer::Config->settings;

However, as Dancer::Config->settings returns us the actual hashref,
we're storing a reference; D::P::EscapeHTML, if automatic_esaping is
enabled, will follow that reference, trampling all over the values of
the settings. 

That, needless to say, is Not Good, and is the cause of the problem.

I think the proper fix is for me to change Dancer::Template::Abstract
to copy the settings rather than storing a reference - e.g.:

    $tokens->{settings} = Clone::clone(Dancer::Config->settings);

In the meantime, I'll also release a new version of D::P::EscapeHTML
which will skip a template tokens key named "settings".

Thanks for spotting & reporting this one :)


Dave P

David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github

More information about the Dancer-users mailing list