Skip to content

Handling events after transaction commit #2324

@jargoud

Description

@jargoud
  • Lunar version: 1.0.3
  • Laravel Version: 12.32.5
  • PHP Version: 8.4.14
  • Database Driver & Version: MariaDB 10.6.23

Expected Behaviour:

When importing products and using database transactions, I would like the PriceObserver events not to be handled before the transaction is commited.

Actual Behaviour:

The SyncPriceCurrencies job fails because is it processed too early by the queue worker:

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\Price]. in /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:780

Laravel provides a ShouldHandleEventsAfterCommit interface to implement by the observer to prevent this behaviour.

Steps To Reproduce:

Create products in a transaction. On Product::create() but before the transaction's commit, the job is dispatched.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions