Skip to content

Jobs are executed multiple times if scheduled in the same transaction using with_delay() #769

@laithfawwaz

Description

@laithfawwaz

Summary:
When calling with_delay() multiple times within the same transaction (i.e., before env.cr.commit()), the queue_job system enqueues and executes each job multiple times based on its position in the list. This results in unintended duplicate executions.

Steps to Reproduce:

record.with_delay().write({})  # Expected: 1 execution, Actual: runs once
record.with_delay().write({})  # Expected: 1 execution, Actual: runs twice
record.with_delay().write({})  # Expected: 1 execution, Actual: runs three times
env.cr.commit()

Expected Behavior:
Each call to with_delay() should schedule exactly one job to be run after commit.

Actual Behavior
Each job appears to be executed multiple times, depending on how many prior with_delay() calls were made in the same transaction. You can observe this by the current retry count on the job record — even though no exceptions are raised that would normally trigger retries.

Environment:
Odoo Version: Odoo 17.0+e-20240201 (Enterprise Edition)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions