queue icon indicating copy to clipboard operation
queue copied to clipboard

[18.0][FIX] queue_job: prevent conflict w/ TestOverrides:test_creates

Open Kimkhoi3010 opened this issue 1 year ago • 2 comments

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).

Kimkhoi3010 avatar Dec 27 '24 05:12 Kimkhoi3010

Hi @guewen, some modules you are maintaining are being modified, check this out!

OCA-git-bot avatar Dec 27 '24 05:12 OCA-git-bot

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.

simahawk avatar Mar 04 '25 08:03 simahawk

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.

github-actions[bot] avatar Jul 06 '25 12:07 github-actions[bot]

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.

amh-mw avatar Jul 07 '25 13:07 amh-mw

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.

Kimkhoi3010 avatar Jul 08 '25 03:07 Kimkhoi3010