From 8f3c6f83bc97dd29287c55263c5a7aa7172b61dd Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Sat, 30 Aug 2025 11:49:28 -0300 Subject: [PATCH] Bug 39190: Fix polymorphic object creation in Koha::Objects This patch fixes polymorphic object creation by ensuring all methods in Koha::Objects that instantiate objects pass the DBIC result to the object_class() method for proper polymorphic resolution. Fixed methods: - find(): Now passes $result to object_class($result) - next(): Now passes $result to object_class($result) - _wrap(): Now passes $_ to object_class($_) in map This enables polymorphic classes like Koha::File::Transports to return the correct subclass (Koha::File::Transport::SFTP, Koha::File::Transport::FTP) based on the transport field value, instead of always returning the base Koha::File::Transport class. To test: 1. Apply the regression tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/File/Transports.t \ t/db_dependent/Koha/File/Transport/SFTP.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/Objects.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 405e6a76679..8bb9c856eb2 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -94,7 +94,7 @@ sub find { unless ( !@pars || none { defined($_) } @pars ) { my $result = $self->_resultset()->find(@pars); if ($result) { - $object = $self->object_class()->_new_from_dbic($result); + $object = $self->object_class($result)->_new_from_dbic($result); } } @@ -319,7 +319,7 @@ sub next { my $result = $self->_resultset()->next(); return unless $result; - my $object = $self->object_class()->_new_from_dbic($result); + my $object = $self->object_class($result)->_new_from_dbic($result); return $object; } @@ -507,7 +507,7 @@ wraps the DBIC object in a corresponding Koha object sub _wrap { my ( $self, @dbic_rows ) = @_; - my @objects = map { $self->object_class->_new_from_dbic($_) } @dbic_rows; + my @objects = map { $self->object_class($_)->_new_from_dbic($_) } @dbic_rows; return @objects; } -- 2.51.0