Skip to content

Commit 4b63583

Browse files
authored
MBS-11472: Do partition_by before converting attribute to JSON
This breaks otherwise since $_->type unsurprisingly expects a blessed reference.
1 parent 37326db commit 4b63583

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/MusicBrainz/Server/Edit/Work.pm

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use List::UtilsBy qw( partition_by );
33
use Moose::Role;
44
use namespace::autoclean;
55

6-
use MusicBrainz::Server::Entity::Util::JSON qw( to_json_object );
6+
use MusicBrainz::Server::Entity::Util::JSON qw( to_json_array );
77
use MusicBrainz::Server::Translation 'l';
88

99
sub edit_category { l('Work') }
@@ -21,16 +21,21 @@ sub grouped_attributes_by_type {
2121
grep { $_ } map { $_->{attribute_value_id} } @$attributes
2222
);
2323

24-
return partition_by { $_->type->l_name } map {
25-
my $attr = MusicBrainz::Server::Entity::WorkAttribute->new(
24+
my %partitioned_attributes = partition_by { $_->type->l_name } map {
25+
MusicBrainz::Server::Entity::WorkAttribute->new(
2626
id => $_->{id},
2727
type_id => $_->{attribute_type_id},
2828
type => $attribute_types->{$_->{attribute_type_id}},
2929
value => $_->{attribute_text} // $attribute_values->{$_->{attribute_value_id}}->value,
3030
value_id => $_->{attribute_value_id}
3131
);
32-
$to_json ? to_json_object($attr) : $attr;
3332
} @$attributes;
33+
34+
if ($to_json) {
35+
%partitioned_attributes = map { $_ => to_json_array($partitioned_attributes{$_}) } keys %partitioned_attributes;
36+
}
37+
38+
return %partitioned_attributes;
3439
}
3540

3641
1;

0 commit comments

Comments
 (0)