We should not cast undefined values to 0.
Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This was a bug I introduced. I think the fix is right, and if something
gets broken for this, it means it was making the wrong assumptions on
the data.
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
use Carp;
use Mojo::JSON;
+use Scalar::Util qw( looks_like_number );
use Try::Tiny;
use Koha::Database;
? Mojo::JSON->true
: Mojo::JSON->false;
}
- elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) ) {
+ elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} )
+ and looks_like_number( $unblessed->{$col} )
+ ) {
# TODO: Remove once the solution for
# https://rt.cpan.org/Ticket/Display.html?id=119904
subtest 'TO_JSON tests' => sub {
- plan tests => 7;
+ plan tests => 8;
$schema->storage->txn_begin;
my $borrowernumber = $builder->build(
{ source => 'Borrower',
value => { lost => 1,
+ sms_provider_id => undef,
gonenoaddress => 0,
updated_on => $dt,
lastseen => $dt, } })->{borrowernumber};
ok( $gonenoaddress->isa('JSON::PP::Boolean'), 'Boolean attribute type is correct' );
is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' );
+ is( $patron->TO_JSON->{sms_provider_id}, undef, 'Undef values should not be casted to 0' );
+
ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
my $rfc3999_regex = qr/