Created attachment 169829 [details] [review] Bug 37510: Unit tests
Created attachment 169830 [details] [review] Bug 37510: Make Koha::Object->delete throw Koha::Exception This patch makes Koha::Object->delete wrap DBIC exceptions on FK constraints and throw a Koha::Exception::Object::FKConstraint exception instead. This will allow us better handling it from the callers. To test: 1. Apply the unit tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Object.t => FAIL: A DBIC exception is thrown instead, tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D
Tests fail even after 2nd patch: t/db_dependent/Koha/Object.t .. 22/23 # Failed test 'threw Koha::Exception' # at t/db_dependent/Koha/Object.t line 1253. # expecting: Koha::Exception # found: normal exit DBIx::Class::Row::update(): Can't update Koha::Schema::Result::BiblioMetadata=HASH(0x63aab4788218): row not found at /kohadevbox/koha/Koha/Object.pm line 172 # Looks like you planned 2 tests but ran 1. # Looks like you failed 1 test of 1 run. # Failed test 'delete() tests' # at t/db_dependent/Koha/Object.t line 1261. DBIx::Class::Row::update(): Can't update Koha::Schema::Result::BiblioMetadata=HASH(0x63aab4788218): row not found at /kohadevbox/koha/Koha/Object.pm line 172 # Looks like your test exited with 255 just after 23. t/db_dependent/Koha/Object.t .. Dubious, test returned 255 (wstat 65280, 0xff00) Failed 1/23 subtests Test Summary Report ------------------- t/db_dependent/Koha/Object.t (Wstat: 65280 (exited 255) Tests: 23 Failed: 1) Failed test: 23 Non-zero exit status: 255 Files=1, Tests=23, 7 wallclock secs ( 0.03 usr 0.02 sys + 3.63 cusr 3.08 csys = 6.76 CPU) Result: FAIL
Created attachment 169842 [details] [review] Bug 37510: Unit tests
Created attachment 169843 [details] [review] Bug 37510: Make Koha::Object->delete throw Koha::Exception This patch makes Koha::Object->delete wrap DBIC exceptions on FK constraints and throw a Koha::Exception::Object::FKConstraint exception instead. This will allow us better handling it from the callers. To test: 1. Apply the unit tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Object.t => FAIL: A DBIC exception is thrown instead, tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D
(In reply to Pedro Amorim from comment #3) > Tests fail even after 2nd patch: > > t/db_dependent/Koha/Object.t .. 22/23 > # Failed test 'threw Koha::Exception' > # at t/db_dependent/Koha/Object.t line 1253. > # expecting: Koha::Exception > # found: normal exit > DBIx::Class::Row::update(): Can't update > Koha::Schema::Result::BiblioMetadata=HASH(0x63aab4788218): row not found at > /kohadevbox/koha/Koha/Object.pm line 172 That's interesting. It seems to me that you don't have 37419 applied and/or missing an `updatedatabase` run. Can you retry with the newer patch (just changed the exception thrown) and provide me more context on how you're running it? Also MariaDB/MySQL version would be helpful. I've tested this with: ```shell $ docker ps | grep db-1 150d15b3232b arm64v8/mariadb:10.5 ... d2812db856b1 arm64v8/mysql:8.0 ... ```
Created attachment 169848 [details] [review] Bug 37510: Unit tests Signed-off-by: David Nind <david@davidnind.com>
Created attachment 169849 [details] [review] Bug 37510: Make Koha::Object->delete throw Koha::Exception This patch makes Koha::Object->delete wrap DBIC exceptions on FK constraints and throw a Koha::Exception::Object::FKConstraint exception instead. This will allow us better handling it from the callers. To test: 1. Apply the unit tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Object.t => FAIL: A DBIC exception is thrown instead, tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: David Nind <david@davidnind.com>
This worked for me by running an updatedatabase after the patches were applied. Note that these warnings were there before the patches were applied: prove t/db_dependent/Koha/Object.t t/db_dependent/Koha/Object.t .. 1/23 Use of uninitialized value in numeric eq (==) at /kohadevbox/koha/Koha/Patron.pm line 446. t/db_dependent/Koha/Object.t .. 7/23 C4::Context->userenv not defined! at /kohadevbox/koha/Koha/Patron.pm line 1891. C4::Context->userenv not defined! at /kohadevbox/koha/Koha/Patron.pm line 1891. t/db_dependent/Koha/Object.t .. 9/23 DBIx::Class::Storage::DBI::insert(): Missing value for primary key column 'currency' on Currency - perhaps you forgot to set its 'is_auto_increment' attribute during add_columns()? Treating 'currency' implicitly as an autoinc, and attempting value retrieval at /kohadevbox/koha/Koha/Object.pm line 172 t/db_dependent/Koha/Object.t .. ok All tests successful. Files=1, Tests=23, 5 wallclock secs ( 0.03 usr 0.01 sys + 3.04 cusr 1.28 csys = 4.36 CPU) Result: PASS
Created attachment 169938 [details] [review] Bug 37510: Unit tests Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Created attachment 169939 [details] [review] Bug 37510: Make Koha::Object->delete throw Koha::Exception This patch makes Koha::Object->delete wrap DBIC exceptions on FK constraints and throw a Koha::Exception::Object::FKConstraint exception instead. This will allow us better handling it from the callers. To test: 1. Apply the unit tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Object.t => FAIL: A DBIC exception is thrown instead, tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
(In reply to Tomás Cohen Arazi from comment #6) > That's interesting. It seems to me that you don't have 37419 applied and/or > missing an `updatedatabase` run. Apologies, yes I was missing the dependency.
Pushed for 24.11! Well done everyone, thank you!
I believe this is related to the failing test on Jenkins: 18:27:32 koha_1 | # Failed test at t/db_dependent/Koha/Objects.t line 773. 18:27:32 koha_1 | # got: 'Koha::Exceptions::Object::FKConstraintDeletion' 18:27:32 koha_1 | # expected: 'DBIx::Class::Exception' 18:27:32 koha_1 | # Looks like you failed 1 test of 7. 18:27:32 koha_1 | 18:27:32 koha_1 | # Failed test 'Koha::Objects->delete' 18:27:32 koha_1 | # at t/db_dependent/Koha/Objects.t line 777. 18:27:32 koha_1 | # Looks like you failed 1 test of 2. 18:27:32 koha_1 | 18:27:32 koha_1 | # Failed test 'Overwritten Koha::Objects->delete - Koha::Patrons' 18:27:32 koha_1 | # at t/db_dependent/Koha/Objects.t line 778. 18:27:32 koha_1 | # Looks like you failed 1 test of 2. 18:27:32 koha_1 | 18:27:32 koha_1 | # Failed test 'Delete' 18:27:32 koha_1 | # at t/db_dependent/Koha/Objects.t line 782. 18:27:32 koha_1 | # Looks like you failed 1 test of 2. 18:27:32 koha_1 | 18:27:32 koha_1 | # Failed test 'Return same values as DBIx::Class' 18:27:32 koha_1 | # at t/db_dependent/Koha/Objects.t line 1065. 18:27:32 koha_1 | # Looks like you failed 1 test of 23. 18:27:32 koha_1 | [16:25:57] t/db_dependent/Koha/Objects.t ............................................... 18:27:32 koha_1 | Dubious, test returned 1 (wstat 256, 0x100) 18:27:32 koha_1 | Failed 1/23 subtests
Created attachment 170464 [details] [review] Bug 37510: Fix Objects.t and remove FIXME This patch makes the tests check for the added exception instead of the generic DBIx::Class::Exception. A FIXME was set in place proposing we should throw a Koha::Exception instead, so removing the FIXME as that's what this patch actually did. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Pushed follow-up, thanks!
Backported to 24.05.x for upcoming 24.05.04
Depends on Bug 37419 not in 23.11.x
No changes required to the manual.