-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The events (DispatchAudit) are missing the SerializesModels trait #890
Comments
Question; with that, wouldn't the |
This is also causing Sanctum tests to fail with the error below after upgrading to the latest version of the package.
Example code: Sanctum::actingAs($user = User::factory()->create());
// Account is auditable
Account::factory()->for($user)->create(); I can confirm that using The ones that have this issue should either downgrade or disable the queueing audits by setting |
Could you test that? |
the dirty values will get lost once a job with |
Feel free to make a PR fixing it |
There are other properties that would be lost besides laravel-auditing/tests/Functional/AuditingTest.php Lines 534 to 539 in 66498a9
|
@cangelis, you seem to understand the problem well, please review #893 |
Actual Behaviour
The constructor of the model is not being called for a queued audit event. As I'm initializing a protected property in the constructor. So, as the contractor is not called that property is never initialized.
This is due to, the
OwenIt\Auditing\Events\DispatchAudit
listener missing theIlluminate\Queue\SerializesModels
trait which results in a large payload for the queue. Also without this, the models are just hydrated/unserialized without calling the construct. Which also makes an issue for me. As I'm initializing a protected property in the constructor. So, as the contractor is not called that property is never initialized.Expected Behaviour
The model should be hydrated from the database instead of just unserializing from the job payload.
Steps to Reproduce
Create an auditable model with a constructor to perform some action. .e.g. to initialize a protected model property.
Then perform some action on model create/update.
You'll notice that the constructor is not called.
Possible Solutions
Please use the
Illuminate\Queue\SerializesModels
trait for both events or at least forOwenIt\Auditing\Events\DispatchAudit
.The text was updated successfully, but these errors were encountered: