Subject: | populate silently drops data if first hashref contains less items than subsequent hashrefs |
When DBIx::Class::ResultSet::populate is calles with an arrayref of hashrefs, it generates a column list from the keys of the first hashref. If the subsequent hashrefs for insertion include hash keys that were not included in the first hashref, but are valid fields, they are silently ignored.
E.g.
Table foo has fields field_1, field_, field_3.
my @populate_items = (
{ field_1=>10, field_3=>30 },
{ field_1=>10, field_2=>20, field_3=>30 }
);
Schema->resultset('Foo')->populate( \@populate_items );
DBIC_TRACE=1 shows the query generated will be equivalent to:
INSERT INTO `foo` ( `field_1`, `field_3` ) VALUES ( ?, ? ): '__BULK_INSERT__'
This has to do with how populate determines the columns in the void context case.
This one bit me pretty hard, I have a populate that happens once a day has a small percentage of it's items missing some views. IF the first item happened to be one missing a field, subsequent items for that populate were all missing that field.
I understand if in the name of keeping this a fast path this behavior needs to stay, but the warning about how context matters should definitely be updated to reflect this case.
Thanks!