[Bug 19686] New: objects.search helper needs a to_model param
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Bug ID: 19686 Summary: objects.search helper needs a to_model param Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST api Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com Bug 19410 introduces a handy helper function to perform searches on Koha::Objects-based clases, plus several add-ons making use of other helpers. But it is still missing the ability to solve field mappings between the exposed API and the DB structure. We should add such a parameter. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |19410 Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19410 [Bug 19410] Add a helper function for generating object searches for the API -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |julian.maurice@biblibre.com | |, lari.taskula@jns.fi, | |matthias.meusburger@biblibr | |e.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #1 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 69315 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=69315&action=edit Bug 19686: Unit tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #2 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 69316 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=69316&action=edit Bug 19686: Add objects.search a 'to_model' param This patch introduces a new parameter to the objects.search Mojo helper. The idea behind this, is that if there's any attribute name mapping between the DB objects and the API exposed ones, we should be able to pass it to objects.search so the filtering query params are mapped correctly for building the DBIC query, like this example: my $patrons_set = Koha::Patrons->new; my @patrons = $c->objects->search( $patrons_set, \&to_model )->as_list; # and probably @patrons = map {to_api($_)} @patrons; The to_model function needs to avoid autovivification, to prevent messing with the query parameters (undef params). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Tests pass! Params get mapped! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tomascohen@gmail.com Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19250 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19250 [Bug 19250] Add pagination to /acquisitions/vendors -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 David Bourgault <david.bourgault@inlibro.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |david.bourgault@inlibro.com Status|Needs Signoff |Patch doesn't apply --- Comment #3 from David Bourgault <david.bourgault@inlibro.com> --- fatal: sha1 information is lacking or useless (t/db_dependent/Koha/REST/Plugin/Objects.t). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Patch doesn't apply |Needs Signoff --- Comment #4 from Tomás Cohen Arazi <tomascohen@gmail.com> --- David, please apply the dependencies in this specific order: - 19234 - 19369 - 19287 - 19370 - 19410 I've just tested it and it applies correctly. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #5 from David Bourgault <david.bourgault@inlibro.com> --- So this fails for me. I get failed test messages that look like this: # Failed test 'exact match for JSON Pointer "/0/firstname"' # at t/db_dependent/Koha/REST/Plugin/Objects.t line 168. # got: 'Emmanuel' # expected: 'Manuel' But I also get this error at the beginning of the prove command: t/db_dependent/Koha/REST/Plugin/Objects.t .. DBD::mysql::st execute failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha_master_dev_inlibro`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) [for Statement "DELETE FROM `borrowers`"] at /usr/local/share/perl/5.22.1/DBIx/Class/Storage/DBI.pm line 1836. No method delete found for Koha::Patrons DBIx::Class::Storage::DBI::_dbh_execute(): Cannot delete or update a parent row: a foreign key constraint fails (`koha_master_dev_inlibro`.`issues`, CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE) at /inlibro/git/koha-master-dev-inlibro/Koha/Objects.pm line 388 at t/db_dependent/Koha/REST/Plugin/Objects.t line 76. Is this a patch error or could it be a DB error? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 David Bourgault <david.bourgault@inlibro.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 David Bourgault <david.bourgault@inlibro.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #69315|0 |1 is obsolete| | --- Comment #6 from David Bourgault <david.bourgault@inlibro.com> --- Created attachment 69463 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=69463&action=edit Bug 19686: Unit tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 David Bourgault <david.bourgault@inlibro.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #69316|0 |1 is obsolete| | --- Comment #7 from David Bourgault <david.bourgault@inlibro.com> --- Created attachment 69464 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=69464&action=edit Bug 19686: Add objects.search a 'to_model' param This patch introduces a new parameter to the objects.search Mojo helper. The idea behind this, is that if there's any attribute name mapping between the DB objects and the API exposed ones, we should be able to pass it to objects.search so the filtering query params are mapped correctly for building the DBIC query, like this example: my $patrons_set = Koha::Patrons->new; my @patrons = $c->objects->search( $patrons_set, \&to_model )->as_list; # and probably @patrons = map {to_api($_)} @patrons; The to_model function needs to avoid autovivification, to prevent messing with the query parameters (undef params). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Tests pass! Params get mapped! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #8 from David Bourgault <david.bourgault@inlibro.com> --- My bad. I tested again with a fresh BD and it worked. Test passed, QA tool green. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19757 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19757 [Bug 19757] Add routes to handle vendor contacts -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |19784 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19784 [Bug 19784] Adapt /v1/patrons to new naming guidelines -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Bug 19686 depends on bug 19410, which changed state. Bug 19410 Summary: Add a helper function for generating object searches for the API https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19410 What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to Master |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|19784 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19784 [Bug 19784] Adapt /v1/patrons to new naming guidelines -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #9 from Tomás Cohen Arazi <tomascohen@gmail.com> --- Created attachment 70626 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=70626&action=edit Bug 19686: (followup) Add to_api param for completeness This patch adds (yet) another param to objects.search: a reference to a to_api function to be applied when processing the search results for output. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Test count raised, and tests pass! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|objects.search helper needs |Add to_model and to_api |a to_model param |params to objects.search | |helper -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact| |julian.maurice@biblibre.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Tomás Cohen Arazi <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |20004 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20004 [Bug 20004] Adapt /v1/cities to new naming guidelines -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #69463|0 |1 is obsolete| | Attachment #69464|0 |1 is obsolete| | Attachment #70626|0 |1 is obsolete| | --- Comment #10 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 71742 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=71742&action=edit Bug 19686: Unit tests Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #11 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 71743 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=71743&action=edit Bug 19686: Add objects.search a 'to_model' param This patch introduces a new parameter to the objects.search Mojo helper. The idea behind this, is that if there's any attribute name mapping between the DB objects and the API exposed ones, we should be able to pass it to objects.search so the filtering query params are mapped correctly for building the DBIC query, like this example: my $patrons_set = Koha::Patrons->new; my @patrons = $c->objects->search( $patrons_set, \&to_model )->as_list; # and probably @patrons = map {to_api($_)} @patrons; The to_model function needs to avoid autovivification, to prevent messing with the query parameters (undef params). To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Tests pass! Params get mapped! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Bourgault <david.bourgault@inlibro.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 --- Comment #12 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 71744 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=71744&action=edit Bug 19686: (followup) Add to_api param for completeness This patch adds (yet) another param to objects.search: a reference to a to_api function to be applied when processing the search results for output. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t => SUCCESS: Test count raised, and tests pass! - Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19686 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to Master --- Comment #13 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- Pushed to master for 18.05, thanks to everybody involved! -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org