diff --git a/lib/OpenQA/Schema/ResultSet/Jobs.pm b/lib/OpenQA/Schema/ResultSet/Jobs.pm index 494ddb1f98d..bc2b3a201b1 100644 --- a/lib/OpenQA/Schema/ResultSet/Jobs.pm +++ b/lib/OpenQA/Schema/ResultSet/Jobs.pm @@ -6,6 +6,7 @@ package OpenQA::Schema::ResultSet::Jobs; use Mojo::Base 'DBIx::Class::ResultSet', -signatures; use DBIx::Class::Timestamps 'now'; use Date::Format 'time2str'; +use Encode qw(decode_utf8); use File::Basename 'basename'; use IPC::Run; use OpenQA::App; @@ -112,7 +113,7 @@ sub create_from_settings { my ($self, $settings, $scheduled_product_id) = @_; my %settings = %$settings; - my %new_job_args = (TEST => $settings{TEST}); + my %new_job_args; my $result_source = $self->result_source; my $schema = $result_source->schema; @@ -171,6 +172,12 @@ sub create_from_settings { } } + for my $key (keys %settings) { + my $value = $settings{$key}; + $settings{$key} = decode_utf8 encode_json $value if (ref $value eq 'ARRAY' || ref $value eq 'HASH'); + } + $new_job_args{TEST} = $settings{TEST}; + # move important keys from the settings directly to the job for my $key (OpenQA::Schema::Result::Jobs::MAIN_SETTINGS) { if (my $value = delete $settings{$key}) { $new_job_args{$key} = $value } diff --git a/t/10-jobs.t b/t/10-jobs.t index 266a235a43c..b6e0079744e 100644 --- a/t/10-jobs.t +++ b/t/10-jobs.t @@ -14,7 +14,6 @@ use FindBin; use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib"; use Mojo::Base -signatures; use autodie ':all'; -use Encode; use File::Copy; use OpenQA::Jobs::Constants; use OpenQA::Test::Case; @@ -26,6 +25,8 @@ use Mojo::JSON qw(decode_json encode_json); use OpenQA::Test::Utils qw(perform_minion_jobs); use OpenQA::Test::TimeLimit '30'; +binmode(STDOUT, ":encoding(UTF-8)"); + my $schema_name = OpenQA::Test::Database::generate_schema_name; my $schema = OpenQA::Test::Case->new->init_data( fixtures_glob => '01-jobs.pl 05-job_modules.pl 06-job_dependencies.pl', @@ -1006,4 +1007,16 @@ subtest 'get all setting values for a job/key in a sorted array' => sub { is_deeply $job_settings->all_values_sorted(99926, 'WORKER_CLASS'), [qw(bar baz foo)], 'all values returned'; }; +subtest 'handling of array and unicode settings' => sub { + my %s = %settings; + $s{TEST} = 'array_setting_test'; + $s{ARRAY_SETTING} = ['value1', 'ä', '…']; + my $job = _job_create(\%s); + my $entry = $job->settings->find({key => 'ARRAY_SETTING'}); + ok $entry, 'ARRAY_SETTING exists in job settings'; + my $v = $entry->value; + is ref($v), '', 'ARRAY_SETTING value is stored as a string'; + is $v, '["value1","ä","…"]', 'retrieved correctly encoded JSON array as string'; +}; + done_testing();