From cf799667e6b582e5528c9619e653e1037b56359a Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Tue, 23 Dec 2025 09:48:05 +0000 Subject: [PATCH 1/3] Update cache to ignore values over 250 characters --- lib/GADS/Datum/Code.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/GADS/Datum/Code.pm b/lib/GADS/Datum/Code.pm index b9555ab75..7ebbb2db0 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 if grep { $_ > 250 } map { length($_) } @values; # We are generally already in a transaction at this point, but # start another one just in case From f3156bb3cc09c973760c54d08c5fae265a5db953 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Mon, 26 Jan 2026 13:59:17 +0000 Subject: [PATCH 2/3] Fix cache code - Fix incorrect return on calc cache code - Add unit test to ensure correct write operation --- lib/GADS/Datum/Code.pm | 2 +- t/007_code_cache.t | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/GADS/Datum/Code.pm b/lib/GADS/Datum/Code.pm index 7ebbb2db0..85abc7f7d 100644 --- a/lib/GADS/Datum/Code.pm +++ b/lib/GADS/Datum/Code.pm @@ -163,7 +163,7 @@ sub write_cache 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 if grep { $_ > 250 } map { length($_) } @values; + 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..36a4259eb 100644 --- a/t/007_code_cache.t +++ b/t/007_code_cache.t @@ -11,6 +11,8 @@ use GADS::Schema; use lib 't/lib'; use Test::GADS::DataSheet; +use Data::Dump qw(pp); + # Populate data with valid countries and not-valid countries. This will change # the number of rows in the database when the return-type changes, as the # non-valid countries will not be written @@ -181,4 +183,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(); From 1e401484d9f4061790f102c55640fdc8d9cdf288 Mon Sep 17 00:00:00 2001 From: Dave Roberts <145559566+droberts-ctrlo@users.noreply.github.com> Date: Mon, 26 Jan 2026 14:12:59 +0000 Subject: [PATCH 3/3] Remove debug dependency left by mistake --- t/007_code_cache.t | 2 -- 1 file changed, 2 deletions(-) diff --git a/t/007_code_cache.t b/t/007_code_cache.t index 36a4259eb..a80898399 100644 --- a/t/007_code_cache.t +++ b/t/007_code_cache.t @@ -11,8 +11,6 @@ use GADS::Schema; use lib 't/lib'; use Test::GADS::DataSheet; -use Data::Dump qw(pp); - # Populate data with valid countries and not-valid countries. This will change # the number of rows in the database when the return-type changes, as the # non-valid countries will not be written