preaction / Minion-Backend-mysql

MySQL backend for the 🐙 Minion job runner
Other
7 stars 14 forks source link

bug with json encoding utf-8 job notes (Wide character in subroutine entry) #32

Closed uralm1 closed 3 years ago

uralm1 commented 3 years ago

Seems https://github.com/brianmed/Minion-Backend-mysql/pull/3 and https://rt.cpan.org/Public/Bug/Display.html?id=108931 returned again in job notes.

In version 7 of db migration - job notes were moved to minion_notes table, note_value column is TEXT. This cause "Wide character in subroutine entry" errors on json conversions. I think changing note_value column to MEDIUMBLOB will fix this issue.

Example:

use Mojolicious::Lite;
plugin Minion => { mysql => 'mysql://user@serv/minion_test_debug' };
app->minion->add_task(poke_mojo => sub {
  my $job = shift;
  $job->app->ua->get('mojolicio.us');
  $job->app->log->debug('We have poked mojo site');
});

get '/' => sub {
  my $c = shift;
  my $id = $c->minion->enqueue('poke_mojo' => [] => {notes=>{mojo=>'rocks', mojo_utf8=>'не работает'}});
  my $j = $c->minion->job($id);
  $c->log->debug('NOTES: '.$j->info->{notes}{mojo});
  $c->render(text=>'We will poke mojo site soon');
};
app->start;

will fail with server error 500:

[2021-02-25 16:47:18.66442] [101561] [info] Listening at "http://*:3000"
Web application available at http://127.0.0.1:3000
[2021-02-25 16:47:21.16330] [101561] [debug] [8DeNEcAp] GET "/"
[2021-02-25 16:47:21.16374] [101561] [debug] [8DeNEcAp] Routing to a callback
Use of Mojo::mysql::PubSub is highly EXPERIMENTAL and should be considered an experiment at /usr/local/share/perl/5.30.0/Mojo/mysql.pm line 39.
[2021-02-25 16:47:21.41053] [101561] [error] [8DeNEcAp] Wide character in subroutine entry at /usr/local/share/perl/5.30.0/Mojo/JSON.pm line 31.

[2021-02-25 16:47:21.41170] [101561] [debug] [8DeNEcAp] Template "exception.development.html.ep" not found
[2021-02-25 16:47:21.41198] [101561] [debug] [8DeNEcAp] Template "exception.html.ep" not found
[2021-02-25 16:47:21.41225] [101561] [debug] [8DeNEcAp] Rendering template "mojo/debug.html.ep"
[2021-02-25 16:47:21.42618] [101561] [debug] Your secret passphrase needs to be changed
[2021-02-25 16:47:21.42800] [101561] [debug] [8DeNEcAp] 500 Internal Server Error (0.264696s, 3.778/s)
preaction commented 3 years ago

Thanks for reporting this! Yes, that sounds like the right solution: It would be a MySQL JSON field, but right now we support MySQL versions before that type existed. Internally, MySQL's JSON type is a binary type, so that would be BLOB, not TEXT.

We'll need a new migration that changes the TEXT column to a MEDIUMBLOB.

preaction commented 3 years ago

I wasn't able to reproduce the problem, unfortunately, so I'm not 100% sure this is a solution for it. But, since I believe you and it's more correct for the column to be a BLOB-like, I've made the change and will upload a release soon.