Bug 18361 - Koha::Objects->find should accept composite primary keys
Summary: Koha::Objects->find should accept composite primary keys
Status: Pushed to Master
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Marcel de Rooy
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on: 18182 18539
Blocks:
  Show dependency treegraph
 
Reported: 2017-03-31 11:46 UTC by Marcel de Rooy
Modified: 2017-06-16 20:05 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 18361: Koha::Objects->find should accept composite primary keys (1.70 KB, patch)
2017-03-31 11:59 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18361: Koha::Objects->find should accept composite primary keys (2.22 KB, patch)
2017-04-13 11:20 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18361: Additional tests for Koha::Objects->find (2.32 KB, patch)
2017-04-13 11:20 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18361: Koha::Objects->find should accept composite primary keys (2.23 KB, patch)
2017-04-19 15:36 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 18361: Additional tests for Koha::Objects->find (2.33 KB, patch)
2017-04-19 15:37 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 18361: (QA followup) Add tests for the no params case (1.27 KB, patch)
2017-04-19 15:37 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 18361: Koha::Objects->find should accept composite primary keys (2.27 KB, patch)
2017-05-01 11:11 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18361: Additional tests for Koha::Objects->find (2.37 KB, patch)
2017-05-01 11:12 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18361: (QA followup) Add tests for the no params case (1.31 KB, patch)
2017-05-01 11:12 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 18361: Koha::Objects->find should accept composite primary keys (2.32 KB, patch)
2017-06-15 16:18 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18361: Additional tests for Koha::Objects->find (2.41 KB, patch)
2017-06-15 16:19 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18361: (QA followup) Add tests for the no params case (1.35 KB, patch)
2017-06-15 16:20 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18361: Koha::Objects->find should accept composite primary keys (2.38 KB, patch)
2017-06-15 18:31 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18361: Additional tests for Koha::Objects->find (2.41 KB, patch)
2017-06-15 18:32 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18361: (QA followup) Add tests for the no params case (1.35 KB, patch)
2017-06-15 18:32 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18361: [QA Follow-up] Resolve warning on undef values supplied (3.00 KB, patch)
2017-06-16 06:19 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel de Rooy 2017-03-31 11:46:52 UTC
Originates from bug 18182. Example is Koha::IssuingRule
Comment 1 Marcel de Rooy 2017-03-31 11:59:29 UTC
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>
Comment 2 Marcel de Rooy 2017-03-31 12:01:44 UTC
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 ;)
Comment 3 Jonathan Druart 2017-03-31 17:54:09 UTC
(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 4 Tomás Cohen Arazi 2017-04-04 13:31:06 UTC
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.
Comment 5 Marcel de Rooy 2017-04-04 13:38:22 UTC Comment hidden (obsolete)
Comment 6 Marcel de Rooy 2017-04-13 11:20:29 UTC
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>
Comment 7 Marcel de Rooy 2017-04-13 11:20:33 UTC
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>
Comment 8 Marcel de Rooy 2017-04-13 11:23:13 UTC
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 :)
Comment 9 Marcel de Rooy 2017-04-13 11:23:49 UTC
(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
Comment 10 Tomás Cohen Arazi 2017-04-19 15:36:54 UTC
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>
Comment 11 Tomás Cohen Arazi 2017-04-19 15:37:01 UTC
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>
Comment 12 Tomás Cohen Arazi 2017-04-19 15:37:49 UTC
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>
Comment 13 Marcel de Rooy 2017-04-20 06:29:15 UTC
(In reply to Tomás Cohen Arazi from comment #12)
> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Thx
Comment 14 Marcel de Rooy 2017-05-01 11:11:58 UTC
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>
Comment 15 Marcel de Rooy 2017-05-01 11:12:03 UTC
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>
Comment 16 Marcel de Rooy 2017-05-01 11:12:07 UTC
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>
Comment 17 Marcel de Rooy 2017-05-01 11:12:44 UTC
Jonathan: Please try again. I actually did not change anything.
Comment 18 Marcel de Rooy 2017-06-02 09:47:28 UTC
ping Jonathan
Comment 19 Jonathan Druart 2017-06-15 16:18:35 UTC
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>
Comment 20 Jonathan Druart 2017-06-15 16:19:26 UTC
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>
Comment 21 Jonathan Druart 2017-06-15 16:20:01 UTC
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>
Comment 22 Jonathan Druart 2017-06-15 18:31:57 UTC
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>
Comment 23 Jonathan Druart 2017-06-15 18:32:03 UTC
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>
Comment 24 Jonathan Druart 2017-06-15 18:32:08 UTC
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>
Comment 25 Jonathan Druart 2017-06-15 18:33:50 UTC
Patches rebased on top of bug 18539
Comment 26 Jonathan Druart 2017-06-15 18:44:10 UTC
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
Comment 27 Marcel de Rooy 2017-06-16 06:18:39 UTC
(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
Comment 28 Marcel de Rooy 2017-06-16 06:19:04 UTC
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>
Comment 29 Jonathan Druart 2017-06-16 20:05:00 UTC
Pushed to master for 17.11, thanks to everybody involved!