Show quoted text> I am not sure what the bugreport is about. The test case you attached
> throws with the correct expected error. Can you elaborate why you
> think this is not the desired behavior?
I have attached an updated test case that should make my point clearer.
The problem is that the test dies if i provide the key with "charfield
=> undef", which is a perfectly valid value and should translate to
NULL (or 'IS NULL') in the database. (see 'M.I.A.' test case).
According to my understanding of DBIC the 'M.I.A.' and 'Robyn' test
cases should behave the same (of course the 'Robyn' find_or_create
statement would produce an invalid sql in the create case)
However it is also ok that an error is thrown if the key is not provided
at all (see 'Santogold' test case)
use strict;
use warnings;
use Test::More;
use Test::Exception;
use lib qw(t/lib);
use DBIC::SqlMakerTest;
use DBICTest;
my $schema = DBICTest->init_schema();
my $artist_rs = $schema->resultset ('Artist');
# Test with charfield NOT NULL
{
my ($artist_ebony_bones1,$artist_ebony_bones2);
$artist_ebony_bones1 = $artist_rs->create({
name => 'Ebony Bones',
rank => 666,
charfield => 'E',
});
$artist_ebony_bones2 = $artist_rs->find_or_create({
name => 'Ebony Bones',
rank => 666,
charfield => 'E', # <- Charfield provided - hence should not die
},{
key => 'u_nullable',
});
is($artist_ebony_bones1->artistid,$artist_ebony_bones2->artistid,'Same artist');
$artist_ebony_bones1->delete;
}
## Test with charfield NOT NULL and provided as undef
#{
# my ($artist_mia1,$artist_mia2);
#
# $artist_mia1 = $artist_rs->create({
# name => 'M.I.A.',
# rank => 555,
# charfield => undef,
# });
#
# $artist_mia2 = $artist_rs->find_or_create({
# name => 'M.I.A.',
# rank => 555,
# charfield => undef, # <- Charfield provided - hence should not die
# },{
# key => 'u_nullable',
# });
#
# is($artist_mia1->artistid,$artist_mia2->artistid,'Same artist');
#
# $artist_mia1->delete();
#}
# Test with charfield NOT NULL and provided as NULL
{
my ($artist_robyn_1,$artist_robyn_2);
$artist_robyn_1 = $artist_rs->create({
name => 'Robyn',
rank => 999,
charfield => \'IS NULL',
});
$artist_robyn_2 = $artist_rs->find_or_create({
name => 'Robyn',
rank => 999,
charfield => \'IS NULL', # <- Charfield provided - hence should not die
},{
key => 'u_nullable',
});
is($artist_robyn_1->artistid,$artist_robyn_2->artistid,'Same artist');
$artist_robyn_1->delete();
}
# Test with charfield NULL and not provided
{
my ($artist_santogold1,$artist_santogold2);
$artist_santogold1 = $artist_rs->create({
name => 'Santogold',
rank => 777,
charfield => undef,
});
throws_ok {
$artist_santogold2 = $artist_rs->find_or_create({
name => 'Santogold',
rank => 777,
# <- Charfield not provided - hence should die
},{
key => 'u_nullable',
});
} qr/Unable to satisfy requested constraint/;
$artist_santogold1->delete();
}
done_testing;