[18.0][FIX] queue_job: prevent conflict w/ TestOverrides:test_creates
Issue:
The native test TestOverrides:test_creates() fails when queue_job is installed due to a security check that prevents the creation of queue.job records via RPC (see queue_job.py#L234). This results in an exception:
ERROR: TestOverrides.test_creates
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/addons/base/tests/test_overrides.py", line 19, in test_creates
model_env.create([]), model_env.browse(),
^^^^^^^^^^^^^^^^^^^^
File "<decorator-gen-160>", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 480, in _model_create_multi
return create(self, arg)
^^^^^^^^^^^^^^^^^
File "/home/odoo/src/user/queue_job_cron_jobrunner/models/queue_job.py", line 147, in create
records = super().create(vals_list)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<decorator-gen-155>", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 480, in _model_create_multi
return create(self, arg)
^^^^^^^^^^^^^^^^^
File "/home/odoo/src/user/queue_job/models/queue_job.py", line 237, in create
raise exceptions.AccessError(
odoo.exceptions.AccessError: Queue jobs must be created by calling 'with_delay()'.
Solution:
- This PR modifies the create method in the queue_job model for that specific case, and only that one (test mode + empty vals_list).
Hi @guewen, some modules you are maintaining are being modified, check this out!
Proposal: use https://github.com/odoo/odoo/blob/18.0/odoo/api.py#L446 and get rid of the sentinel.
As an alternative we could use rpc_helper but that would add another dependency.
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.
It's inevitable that not all post-install tests from core Odoo run successfully on a database with additional modules involved. If this causes issues in your setup, I would recommend to only run the tests of your custom modules (or, custom + OCA modules).
@StefanRijnhart As another fool that has been tilting at the core Odoo test windmill for several years now, I agree that some failures are inevitable, but still find a lot of value in running the majority of the tests and only excluding (i.e. --test-tags=-/base.test_creates) or patching out the absolutely irreconcilable ones. Especially when migrating Odoo versions, I have found tests invaluable for detecting drift between the core Odoo implementation and custom modules built on top of that implementation.
This PR is closed in favor of #802, which supersedes and includes the necessary fixes and improvements. Thanks to @amh-mw for taking it over and refining the solution.