Bugzilla – Attachment 64372 Details for
Bug 18361
Koha::Objects->find should accept composite primary keys
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18361: [QA Follow-up] Resolve warning on undef values supplied
Bug-18361-QA-Follow-up-Resolve-warning-on-undef-va.patch (text/plain), 3.00 KB, created by
Marcel de Rooy
on 2017-06-16 06:19:04 UTC
(
hide
)
Description:
Bug 18361: [QA Follow-up] Resolve warning on undef values supplied
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-06-16 06:19:04 UTC
Size:
3.00 KB
patch
obsolete
>From c62b7a8cafc56f20c20d5e78a27de2abe7382abb Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 16 Jun 2017 07:57:14 +0200 >Subject: [PATCH] Bug 18361: [QA Follow-up] Resolve warning on undef values > supplied >Content-Type: text/plain; charset=utf-8 > >The following warning was raised in Letters.t: >DBIx::Class::ResultSource::_minimal_valueset_satisfying_constraint(): >NULL/undef values supplied for requested unique constraint 'primary' (NULL >values in column(s): 'id'). This is almost certainly not what you wanted, >though you can set DBIC_NULLABLE_KEY_NOWARN to disable this warning. > >This warning is triggered by this line in C4/Letters.pm: > Koha::SMS::Providers->find( $member->{'sms_provider_id'} ); >As you already guessed, the sms_provider_id returns undef. > >Resolved in sub find by testing if there are parameters and if so, they >should not be all undefined. (In most cases there will be only one >parameter; but this report is about composite keys.) > >Added a trivial test case in Objects.t too. > >Test plan: >Run t/db_dependent/Koha/Object.t >Run t/db_dependent/Koha/Objects.t >Run t/db_dependent/Letters.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Objects.pm | 3 ++- > t/db_dependent/Koha/Objects.t | 8 +++++++- > 2 files changed, 9 insertions(+), 2 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index ff1a7e5..193e494 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -20,6 +20,7 @@ package Koha::Objects; > use Modern::Perl; > > use Carp; >+use List::MoreUtils qw( none ); > > use Koha::Database; > >@@ -86,7 +87,7 @@ sub find { > > croak 'Cannot use "->find" in list context' if wantarray; > >- return unless @pars; >+ return if !@pars || none { defined($_) } @pars; > > my $result = $self->_resultset()->find( @pars ); > >diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t >index 0f5926d..f5f9472 100644 >--- a/t/db_dependent/Koha/Objects.t >+++ b/t/db_dependent/Koha/Objects.t >@@ -45,13 +45,19 @@ my $borrowernumber_exists = grep { /^borrowernumber$/ } @columns; > is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table columns' ); > > subtest 'find' => sub { >- plan tests => 2; >+ plan tests => 4; > my $patron = $builder->build({source => 'Borrower'}); > my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); > is( $patron_object->borrowernumber, $patron->{borrowernumber}, '->find should return the correct object' ); > > eval { my @patrons = Koha::Patrons->find( $patron->{borrowernumber} ); }; > like( $@, qr|^Cannot use "->find" in list context|, "->find should not be called in list context to avoid side-effects" ); >+ >+ # Test sending undef to find; should not generate a warning >+ warning_is { $patron = Koha::Patrons->find( undef ); } >+ "", "Sending undef does not trigger a DBIx warning"; >+ warning_is { $patron = Koha::Patrons->find( undef, undef ); } >+ "", "Sending two undefs does not trigger a DBIx warning too"; > }; > > subtest 'update' => sub { >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18361
:
61754
|
62142
|
62143
|
62395
|
62396
|
62397
|
62909
|
62910
|
62911
|
64339
|
64340
|
64341
|
64347
|
64348
|
64349
| 64372 |
66006