|
11 | 11 | from odoo.addons.queue_job.delay import DelayableGraph |
12 | 12 | from odoo.addons.queue_job.exception import ( |
13 | 13 | FailedJobError, |
| 14 | + JobMethodNotFound, |
14 | 15 | NoSuchJobError, |
15 | 16 | RetryableJobError, |
16 | 17 | ) |
@@ -304,6 +305,32 @@ def test_job_unlinked(self): |
304 | 305 | with self.assertRaises(NoSuchJobError): |
305 | 306 | Job.load(self.env, test_job.uuid) |
306 | 307 |
|
| 308 | + def _create_non_existing_method_job(self): |
| 309 | + test_job = Job(self.method) |
| 310 | + test_job.store() |
| 311 | + self.env.cr.execute( |
| 312 | + "UPDATE queue_job SET method_name = %s WHERE uuid = %s", |
| 313 | + ("nonexistent_xyz", test_job.uuid), |
| 314 | + ) |
| 315 | + self.env["queue.job"].invalidate_model() |
| 316 | + return test_job.uuid |
| 317 | + |
| 318 | + def test_load_missing_method(self): |
| 319 | + """Job.load raises JobMethodNotFound when the method is missing.""" |
| 320 | + uuid = self._create_non_existing_method_job() |
| 321 | + with self.assertRaises(JobMethodNotFound): |
| 322 | + Job.load(self.env, uuid) |
| 323 | + |
| 324 | + def test_load_many_skips_missing_method(self): |
| 325 | + """load_many skips a broken job — other jobs still load.""" |
| 326 | + good = Job(self.method) |
| 327 | + good.store() |
| 328 | + bad_uuid = self._create_non_existing_method_job() |
| 329 | + loaded = Job.load_many(self.env, [good.uuid, bad_uuid]) |
| 330 | + loaded_uuids = {j.uuid for j in loaded} |
| 331 | + self.assertIn(good.uuid, loaded_uuids) |
| 332 | + self.assertNotIn(bad_uuid, loaded_uuids) |
| 333 | + |
307 | 334 | def test_unicode(self): |
308 | 335 | test_job = Job( |
309 | 336 | self.method, |
@@ -571,6 +598,16 @@ def test_requeue(self): |
571 | 598 | stored.requeue() |
572 | 599 | self.assertEqual(stored.state, PENDING) |
573 | 600 |
|
| 601 | + def test_change_state_skips_missing_method(self): |
| 602 | + """_change_job_state does not crash when the method is missing.""" |
| 603 | + stored = self._create_job() |
| 604 | + self.env.cr.execute( |
| 605 | + "UPDATE queue_job SET method_name = %s WHERE uuid = %s", |
| 606 | + ("vanished_xyz", stored.uuid), |
| 607 | + ) |
| 608 | + self.env["queue.job"].invalidate_model() |
| 609 | + stored.button_done() |
| 610 | + |
574 | 611 | def test_requeue_wait_dependencies_not_touched(self): |
575 | 612 | job_root = Job(self.env["test.queue.job"].testing_method) |
576 | 613 | job_child = Job(self.env["test.queue.job"].testing_method) |
|
0 commit comments