Bug 40136: (follow-up) Stringify DateTime objects in _unblessed_for_log

Koha::Object::AUTOLOAD calls set_column directly, bypassing DBIC's
inflate/deflate mechanism. This means date/datetime column values set
via Koha object accessors (without store()) can end up as raw DateTime
objects in _column_data. When _unblessed_for_log then calls get_column,
it retrieves the DateTime object, which encode_json in C4::Log cannot
serialise, causing the patron delete (and test) to die with an
"encountered object" error.

Fix by stringifying any DateTime objects found in the column data before
returning from _unblessed_for_log.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-03-26 09:19:07 +01:00
parent 9e8eceb1a7
commit eb36400a9b
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
1 changed files with 7 additions and 0 deletions

View File

@ -3762,6 +3762,13 @@ sub _unblessed_for_log {
my %data = map { $_ => $self->get_column($_) } $self->{_result}->result_source->columns;
delete @data{qw(password lastseen updated_on)};
for my $key ( keys %data ) {
# Koha::Object::AUTOLOAD calls set_column directly (bypassing DBIC deflation),
# so date/datetime columns set via Koha accessors may hold DateTime objects
# in _column_data. Stringify them so encode_json doesn't choke.
if ( ref $data{$key} && $data{$key}->isa('DateTime') ) {
$data{$key} = "$data{$key}";
}
delete $data{$key} unless defined $data{$key} && $data{$key} ne '';
}
return \%data;