Bug 32745

Summary: Jobs view breaks when there are jobs with context IS NULL
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: System AdministrationAssignee: Jonathan Druart <jonathan.druart>
Status: RESOLVED FIXED QA Contact: Katrin Fischer <katrin.fischer>
Severity: normal    
Priority: P5 - low CC: cmurdock, david, gmcharlt, jonathan.druart, nick
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.06
Attachments: Bug 32745: Adjust context for invalid background jobs
Bug 32745: Adjust context for invalid background jobs
Bug 32745: Adjust context for invalid background jobs

Description Katrin Fischer 2023-01-30 14:56:13 UTC
In 22.11.01 the background jobs view breaks, when there are entries with context = NULL in the database. In our case these are old entries for "batch_biblio_record_modification" from 2021. Newer entries seem to always have context set. Maybe an update issue with old data?

* Manipulate database
* Go to Administration > Manage jobs
* Uncheck both checkboxes on top of the list if necessary
Comment 1 Katrin Fischer 2023-03-23 14:55:52 UTC
Any idea about this one? I think I saw something similar on the mailing list too.
Comment 2 Jonathan Druart 2023-03-24 10:21:18 UTC
Created attachment 148643 [details] [review]
Bug 32745: Adjust context for invalid background jobs

We had some problems recently and it's possible to have
background_jobs.context=NULL
But the REST API specs is expecting an object.
We could either modify the specs, or adjust the incorrect entries in DB,
which is IMO better.

Test plan:
0. Don't apply the patch
1. Create some background jobs
2. Set context to NULL
UPDATE background_jobs SET context=NULL;
3. List the jobs and note the datatable error, and the error in Koha log
  OpenAPI >>> GET api/v1/jobs [{"message":"Expected object - got null.","path":"\/body\/0\/context"},{"message":"Expected object - got null.","path":"\/body\/1\/context"}]

4. Apply the patch
5. Run `updatedatabase`
6. Confirm that the list and detail view are not working correctly
Comment 3 David Nind 2023-04-23 06:55:26 UTC
Created attachment 150115 [details] [review]
Bug 32745: Adjust context for invalid background jobs

We had some problems recently and it's possible to have
background_jobs.context=NULL
But the REST API specs is expecting an object.
We could either modify the specs, or adjust the incorrect entries in DB,
which is IMO better.

Test plan:
0. Don't apply the patch
1. Create some background jobs
2. Set context to NULL
UPDATE background_jobs SET context=NULL;
3. List the jobs and note the datatable error, and the error in Koha log
  OpenAPI >>> GET api/v1/jobs [{"message":"Expected object - got null.","path":"\/body\/0\/context"},{"message":"Expected object - got null.","path":"\/body\/1\/context"}]

4. Apply the patch
5. Run `updatedatabase`
6. Confirm that the list and detail view are not working correctly

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2023-04-23 06:57:52 UTC
Testing notes (using KTD):

1. To create some background jobs, I started KTD with --es7 then updated the titles for 3 records.

2. For step 6 of the test plan, I think that should say the list and detail views ARE working correctly 8-).
Comment 5 Katrin Fischer 2023-04-23 10:08:00 UTC
Created attachment 150118 [details] [review]
Bug 32745: Adjust context for invalid background jobs

We had some problems recently and it's possible to have
background_jobs.context=NULL
But the REST API specs is expecting an object.
We could either modify the specs, or adjust the incorrect entries in DB,
which is IMO better.

Test plan:
0. Don't apply the patch
1. Create some background jobs
2. Set context to NULL
UPDATE background_jobs SET context=NULL;
3. List the jobs and note the datatable error, and the error in Koha log
  OpenAPI >>> GET api/v1/jobs [{"message":"Expected object - got null.","path":"\/body\/0\/context"},{"message":"Expected object - got null.","path":"\/body\/1\/context"}]

4. Apply the patch
5. Run `updatedatabase`
6. Confirm that the list and detail view are not working correctly

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 6 Katrin Fischer 2023-04-23 10:08:28 UTC
Are we missing a 'success' message in the database update? (is the second output line manatory?)
Comment 7 Tomás Cohen Arazi 2023-05-05 12:17:01 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 8 Martin Renvoize 2023-05-11 12:25:36 UTC
Many hands makes light work, thankyou everyone!

Pushed to 22.11.x for the next release