From 4e72c505776f6213a25526630e2e978fcfbc016d Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 2 Feb 2024 09:02:59 +0200 Subject: [PATCH] Bug 32132: Do not allow NULL value in column aqbudgets.budget_period_id If budget_period_id column is set as NULL, "Late orders" page dies on error 500. Logs read: Template process failed: undef error - DBIC result _type isn't of the _type Aqbudget at /home/koha/Koha/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt line 157 This patch makes changes to column aqbudgets.budget_period_id so that it no longer allows NULL values. This is in line with aqbudgets tables foreign key "budget_period_id" which has ON DELETE CASCADE clause. To test: 1. Run prove t/db_dependent/Koha/Acquisition/Fund.t => Tests should fail 2. Run updatedatabase.pl and restart services if needed 3. Rerun prove t/db_dependent/Koha/Acquisition/Fund.t => Tests should now pass Sponsored-by: Koha-Suomi Oy --- installer/data/mysql/atomicupdate/bug_32132.pl | 17 +++++++++++++++++ t/db_dependent/Koha/Acquisition/Fund.t | 11 ++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_32132.pl diff --git a/installer/data/mysql/atomicupdate/bug_32132.pl b/installer/data/mysql/atomicupdate/bug_32132.pl new file mode 100755 index 0000000000..f85fb7e084 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_32132.pl @@ -0,0 +1,17 @@ +use Modern::Perl; + +return { + bug_number => "32132", + description => "Set aqbudgets.budget_period_id as NOT NULL", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Do you stuffs here + $dbh->do(q{ALTER TABLE aqbudgets MODIFY COLUMN `budget_period_id` INT(11) NOT NULL}); + + # Print useful stuff here + # tables + say $out "Change aqbudgets.budget_period_id to NOT accept NULL values."; + }, +}; diff --git a/t/db_dependent/Koha/Acquisition/Fund.t b/t/db_dependent/Koha/Acquisition/Fund.t index 80c4e4e65a..fc21d0b38f 100755 --- a/t/db_dependent/Koha/Acquisition/Fund.t +++ b/t/db_dependent/Koha/Acquisition/Fund.t @@ -20,6 +20,7 @@ use Modern::Perl; use Test::More tests => 3; +use Test::Warn; use t::lib::TestBuilder; @@ -57,7 +58,7 @@ subtest 'budget ()' => sub { }; subtest 'budget' => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin; my $f = $builder->build_object( @@ -70,5 +71,13 @@ subtest 'budget' => sub { is( ref( $fund->budget ), 'Koha::Acquisition::Budget', '->fund should return a Koha::Acquisition::Budget object' ); + + # Cannot set aqbudgets.budget_period_id as NULL + warning_like { + eval { $fund->budget_period_id(undef)->store } + } + qr{.*DBD::mysql::st execute failed: Column 'budget_period_id' cannot be null.*}, + 'DBD should have raised an error about budget_period_id that cannot be null'; + $schema->storage->txn_rollback; }; -- 2.34.1