Skip to content
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

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

Closed
janklan opened this issue Oct 29, 2024 · 1 comment · Fixed by #228
Closed

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

janklan opened this issue Oct 29, 2024 · 1 comment · Fixed by #228
Labels
bug Something isn't working

Comments

@janklan
Copy link
Contributor

janklan commented Oct 29, 2024

Q A
auditor version 3.2.0 (introduced in #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.

@janklan janklan added the bug Something isn't working label Oct 29, 2024
janklan added a commit to janklan/auditor that referenced this issue Oct 29, 2024
janklan added a commit to janklan/auditor that referenced this issue Oct 29, 2024
DamienHarper added a commit that referenced this issue Oct 31, 2024
* Strengthen type checking in AuditTrait

Fixes #227

* PHP-CS-Fixer

---------

Co-authored-by: Damien Harper <[email protected]>
@DamienHarper
Copy link
Owner

Fixed in 3.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants