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

JsonException when using custom binary DoctrineType #106

Open
zoka123 opened this issue May 29, 2022 · 3 comments
Open

JsonException when using custom binary DoctrineType #106

zoka123 opened this issue May 29, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@zoka123
Copy link

zoka123 commented May 29, 2022

Q A
auditor version 2.0.3
PHP version 8.1.2
Database SQLite

Summary

It fails to compute the diff when a custom Doctrine type mapped to binary database type is used. It checks for known types such as Ramsey or Symfony UUIDs, but doesn't provide for customization when it comes to custom types - it defaults to using convertToDatabaseValue for all the unknown types.

convertToDatabaseValue in this case is returning a binary value which breaks JSON encoding further down the line.

Current behavior

A custom doctrine type, e.g. a copy of AbstractUid would cause the following exception:

JsonException: Malformed UTF-8 characters, possibly incorrectly encoded

/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php:221
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php:66
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php:139
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php:38
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionManager.php:32
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Event/DoctrineSubscriber.php:43
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Logger/Logger.php:28
/opt/app/vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Logger/LoggerChain.php:30
/opt/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1783
/opt/app/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:454
/opt/app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:398
/opt/app/var/cache/test/ContainerPGPpJpP/EntityManager_9a5be93.php:136

How to reproduce

  1. Create a custom Doctrine type extending AbstractUid
  2. Persist and flush the entity
  3. See JsonException: Malformed UTF-8 characters, possibly incorrectly encoded

Expected behavior

  1. Create a custom Doctrine type extending AbstractUid
  2. Persist and flush the entity
  3. See audit entry created

We could maybe introduce an interface that could be used with custom types, and checked here?

@zoka123 zoka123 added the bug Something isn't working label May 29, 2022
@DamienHarper
Copy link
Owner

@zoka123 thanks for the report, will have a look at it shortly

@DamienHarper
Copy link
Owner

@zoka123 First, I'm sorry for that very late response.
I can't find a way to reproduce this issue, it might already have been solved since you opened it.
Do you still face this issue?

@pedrocasado
Copy link

i had this problem today. i couldn't reproduce the error in dev environment yet and looks like my problem is not related with uuid's.

JsonException: Malformed UTF-8 characters, possibly incorrectly encoded

#21 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php(223): json_encode
#20 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php(223): DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionProcessor::audit
#19 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php(67): DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionProcessor::insert
#18 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php(140): DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionProcessor::processInsertions
#17 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionProcessor.php(39): DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionProcessor::process
#16 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/TransactionManager.php(32): DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionManager::process
#15 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Event/DoctrineSubscriber.php(57): DH\Auditor\Provider\Doctrine\Auditing\Event\DoctrineSubscriber::DH\Auditor\Provider\Doctrine\Auditing\Event\{closure}
#14 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Logger/Logger.php(25): DH\Auditor\Provider\Doctrine\Auditing\Logger\Logger::startQuery
#13 /vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Logger/LoggerChain.php(27): DH\Auditor\Provider\Doctrine\Auditing\Logger\LoggerChain::startQuery
#12 /vendor/doctrine/dbal/src/Connection.php(1459): Doctrine\DBAL\Connection::doCommit
#11 /vendor/doctrine/dbal/src/Connection.php(1420): Doctrine\DBAL\Connection::commit
#10 /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(469): Doctrine\ORM\UnitOfWork::commit
#9 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(403): Doctrine\ORM\EntityManager::flush

php 8.1.2
auditor 2.4.7
auditor-bundle 5.2.4

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

No branches or pull requests

3 participants