owen-it / laravel-auditing

Record the change log from models in Laravel
https://laravel-auditing.com
MIT License
3.01k stars 387 forks source link

Enabling queue causes Unable to JSON encode payload. Error (5) #885

Closed danharper83 closed 4 months ago

danharper83 commented 9 months ago

After updating to the latest version it seems that the queue is automatically enabled.

This caused all my auditable models to stop saving and return this error:

Unable to JSON encode payload. Error (5): Malformed UTF-8 characters, possibly incorrectly encoded {"userId":1,"exception":"[object] (Illuminate\\Queue\\InvalidPayloadException(code: 0): Unable to JSON encode payload. Error (5): Malformed UTF-8 characters, possibly incorrectly encoded at /app/vendor/laravel/framework/src/Illuminate/Queue/Queue.php:109)

Publishing the config and setting the queue to false solves the issue but it's not clear why this is happening.

laravel/framework v10.38.1 owen-it/laravel-auditing v13.6.3

Thanks Dan

parallels999 commented 9 months ago

Your json is not utf-8, check db encoding, json encoding

danharper83 commented 9 months ago

The database is utf8_unicode_ci

Everything works as expected when the queue is turned off, the audits are written to the audit table correctly. This issue only started when I upgraded to the latest version which has the queue configuration set to true by default.

parallels999 commented 9 months ago

Difficult to reproduce without the model to verify what data the malformed UTF-8 has, if you can upload an example in a clean installation showing the problem it would be very helpful

djibrilcolynat commented 9 months ago

I just opened an issue for the same reason. Guys, something broke in new updates. I reverted to version 13.5.1 and things went back working fine. I used binary uuid (Dyryndra/laravel-efficient-uuid), but I notice that the "Malformed character" error comes from the fact that binary uuid in models are not longer casted into string using the custom caster I provided in attributedMotifiers property. So trying to encode bytes in JSON will result in a "Malformed character" error

parallels999 commented 9 months ago

Could you try #893

https://github.com/owen-it/laravel-auditing/issues/884#issuecomment-1866373894

djibrilcolynat commented 9 months ago

@parallels999 It didn't work either. Have to temporarily stick to v13.5.1 in production.

MortenDHansen commented 9 months ago

I have released 13.6.4 where the queue feature is disabled by default (as it should have been, sorry). I expect avoiding the serialization for queue should mitigate the problem. If not, let me know and stick to v13.5.1 in production.