DamienHarper / auditor

auditor, the missing audit log library
MIT License
164 stars 53 forks source link

Broken JSON change detection when the JSON value is not an array. #227

Closed janklan closed 3 weeks ago

janklan commented 3 weeks ago
Q A
auditor version 3.2.0 (introduced in https://github.com/DamienHarper/auditor/pull/225)
PHP version 8.3.13
Database PostgreSQL

Summary

I'm getting an error from Auditor: DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionProcessor::deepDiff(): Argument #2 ($new) must be of type ?array, string given, called in /srv/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php on line 210

It's caused by an incorrect assumption that the Doctrine's JSON object can only contain iterables. A string, boolean and a number is a perfectly valid JSON value the field supports. Whether or not it is weird to save a string as a JSON type is out of the scope of this bug report. The fact is that doing so possible, and so it should be handled, edge-case or not.

Current behavior

When auditing an entity holding a string in a json Doctrine property, Auditor passess the value to AuditTrait::deepDiff(), which has (?array, ?array) signature.

How to reproduce

Add a string property mapped as JSON column and trigger auditing.

Expected behavior

Auditor should survive a string stored in a JSON column.

DamienHarper commented 3 weeks ago

Fixed in 3.3.0