diff --git a/lib/GADS/Datum/Code.pm b/lib/GADS/Datum/Code.pm index b9555ab75..85abc7f7d 100644 --- a/lib/GADS/Datum/Code.pm +++ b/lib/GADS/Datum/Code.pm @@ -162,6 +162,8 @@ sub write_cache my $formatter = $self->schema->storage->datetime_parser; my @values = sort @{$self->value} if defined $self->value->[0]; + # If the length is greater than 250 characters do not insert it to the cache table + return \@values if grep { $_ > 250 } map { length($_) } @values; # We are generally already in a transaction at this point, but # start another one just in case diff --git a/t/007_code_cache.t b/t/007_code_cache.t index f019ad876..a80898399 100644 --- a/t/007_code_cache.t +++ b/t/007_code_cache.t @@ -181,4 +181,24 @@ is_deeply([map $_->value_int, $urs->all], $expected, "Correct values for cached is_deeply([map $_->value_text, $urs->all], $expected, "Correct values for cached table after change to int"); } +{ + my $expected_calc_val = "This is a really long string, longer than before, to test caching of long strings should fail gracefully and not put any extra values in the cache, this is to test the edge case handling of long strings in cached unique values because they break the cache in some really weird ways sometimes"; + $record->clear; + $record->find_current_id(1); + $calc1->code(" + function evaluate (L1string1) + return L1string1 + end + "); + $calc1->return_type('string'); + $calc1->write; + $record->fields->{$string1->id}->set_value($expected_calc_val); + $record->write(no_alerts => 1); + + is_deeply([map $_->value_text, $urs->all], [qw/Bar7 Bar8/], "Correct values for cached table after long string write"); + + my $calc_val = $record->fields->{$string1->id}->as_string; + is($calc_val, $expected_calc_val, "Correct value returned from calc after long string write"); +} + done_testing();