Originates from bug 18182. Example is Koha::IssuingRule
Created attachment 61754 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
The indirect way of testing the changed find via TestBuilder works. Is it enough or should we add find tests in Koha/Objects.t? Note that I perhaps would have expected such a subtest already, but it does not exist ;)
(In reply to Marcel de Rooy from comment #2) > The indirect way of testing the changed find via TestBuilder works. > Is it enough or should we add find tests in Koha/Objects.t? > Note that I perhaps would have expected such a subtest already, but it does > not exist ;) Yes we should definitely have one in Objects.t
Comment on attachment 61754 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys > sub find { >- my ( $self, $id ) = @_; >+ my ( $self, @id ) = @_; While I agree with the general idea, I'd prefer that we keep in mind that this is a passthrough to DBIC ->find method. In that sense, please look at ResultSet.pm: sub find { my $self = shift; my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}); IMHO we should implement exactly that, probably accept whatever is passed to K:O->find and just pass it to RS->find.
(In reply to Tomás Cohen Arazi from comment #4) > Comment on attachment 61754 [details] [review] [review] > Bug 18361: Koha::Objects->find should accept composite primary keys > > > sub find { > >- my ( $self, $id ) = @_; > >+ my ( $self, @id ) = @_; > > While I agree with the general idea, I'd prefer that we keep in mind that > this is a passthrough to DBIC ->find method. In that sense, please look at > ResultSet.pm: > > sub find { > my $self = shift; > my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}); > > IMHO we should implement exactly that, probably accept whatever is passed to > K:O->find and just pass it to RS->find. my $result = $self->_resultset()->find(@id); So we pass them to RS. What is exactly your point ?
Created attachment 62142 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Also adjusted the POD section to show more clearly that we accept the same parameters as DBIx ResultSet does. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Created attachment 62143 [details] [review] Bug 18361: Additional tests for Koha::Objects->find Adding a subtest find in t/db_dependent/Koha/Objects.t. Test plan: Run t/db_dependent/Koha/Objects.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tomas: I adjusted the POD to make your concerns more visible, and renamed the @id array to a more generic name @pars, since it indeed may contain an attrs hash. Additionally, I added a find subtest in Objects.t that contains a few tests where an attr hash is passed along to find. Signoff time :)
(In reply to Jonathan Druart from comment #3) > (In reply to Marcel de Rooy from comment #2) > > The indirect way of testing the changed find via TestBuilder works. > > Is it enough or should we add find tests in Koha/Objects.t? > > Note that I perhaps would have expected such a subtest already, but it does > > not exist ;) > > Yes we should definitely have one in Objects.t Done
Created attachment 62395 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Also adjusted the POD section to show more clearly that we accept the same parameters as DBIx ResultSet does. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 62396 [details] [review] Bug 18361: Additional tests for Koha::Objects->find Adding a subtest find in t/db_dependent/Koha/Objects.t. Test plan: Run t/db_dependent/Koha/Objects.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 62397 [details] [review] Bug 18361: (QA followup) Add tests for the no params case This patch adds a test for the trivial case in which no param is passed and the ->find method returns undef. For completeness purposes. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(In reply to Tomás Cohen Arazi from comment #12) > Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Thx
Created attachment 62909 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Also adjusted the POD section to show more clearly that we accept the same parameters as DBIx ResultSet does. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 62910 [details] [review] Bug 18361: Additional tests for Koha::Objects->find Adding a subtest find in t/db_dependent/Koha/Objects.t. Test plan: Run t/db_dependent/Koha/Objects.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 62911 [details] [review] Bug 18361: (QA followup) Add tests for the no params case This patch adds a test for the trivial case in which no param is passed and the ->find method returns undef. For completeness purposes. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Jonathan: Please try again. I actually did not change anything.
ping Jonathan
Created attachment 64339 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Also adjusted the POD section to show more clearly that we accept the same parameters as DBIx ResultSet does. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64340 [details] [review] Bug 18361: Additional tests for Koha::Objects->find Adding a subtest find in t/db_dependent/Koha/Objects.t. Test plan: Run t/db_dependent/Koha/Objects.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64341 [details] [review] Bug 18361: (QA followup) Add tests for the no params case This patch adds a test for the trivial case in which no param is passed and the ->find method returns undef. For completeness purposes. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64347 [details] [review] Bug 18361: Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Also adjusted the POD section to show more clearly that we accept the same parameters as DBIx ResultSet does. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64348 [details] [review] Bug 18361: Additional tests for Koha::Objects->find Adding a subtest find in t/db_dependent/Koha/Objects.t. Test plan: Run t/db_dependent/Koha/Objects.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Created attachment 64349 [details] [review] Bug 18361: (QA followup) Add tests for the no params case This patch adds a test for the trivial case in which no param is passed and the ->find method returns undef. For completeness purposes. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Patches rebased on top of bug 18539
I get warnings from tests: t/db_dependent/Letters.t ..................................... 3/82 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. at /home/vagrant/kohaclone/Koha/Objects.pm line 91
(In reply to Jonathan Druart from comment #26) > I get warnings from tests: > > t/db_dependent/Letters.t ..................................... 3/82 > 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. at > /home/vagrant/kohaclone/Koha/Objects.pm line 91 Good catch
Created attachment 64372 [details] [review] Bug 18361: [QA Follow-up] Resolve warning on undef values supplied 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>
Pushed to master for 17.11, thanks to everybody involved!
Enhancement not pushed to 17.05.x
I finally to push to 17.05.x in order to follow master using this change. Will be in 17.05.03.
Conflicts with 16.11.x. If you want this to be included, please rebase on 16.11.x. Thx!
Created attachment 66006 [details] [review] Bug 18361: [SQUASHED FOR 16.11] Koha::Objects->find should accept composite primary keys Changes the $id parameter to an array. (IssuingRule has three keys.) The build_object method in TestBuilder.pm has been adjusted to pass multiple primary key values to find. Also adjusted the POD section to show more clearly that we accept the same parameters as DBIx ResultSet does. Test plan: Run t/db_dependent/Koha/Object.t Run t/db_dependent/Koha/Objects.t Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Bug 18361: Additional tests for Koha::Objects->find Adding a subtest find in t/db_dependent/Koha/Objects.t. Test plan: Run t/db_dependent/Koha/Objects.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Bug 18361: (QA followup) Add tests for the no params case This patch adds a test for the trivial case in which no param is passed and the ->find method returns undef. For completeness purposes. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Bug 18361: [QA Follow-up] Resolve warning on undef values supplied 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>
(In reply to Katrin Fischer from comment #32) > Conflicts with 16.11.x. If you want this to be included, please rebase on > 16.11.x. Thx! That you should do it..
Thx Marcel - patches apply now and tests pass. This patch has been pushed to 16.11.x and will be in 16.11.11.