-
Notifications
You must be signed in to change notification settings - Fork 121
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
Comparison of the diff from decimal fields are being applied even when value is the same #299
Comments
@pedrocasado Thanks for the report, could you please tell me what Edit: it seems that you use default values ( |
@DamienHarper , yes. I'm not passing then, so i'm using the default ones.
|
It seems that this bug is coming from the Doctrine Bundle. I found this stackoverflow link referencing the same issue: https://stackoverflow.com/questions/33773066/symfony-doctrine-detects-change-in-money-field-even-when-no-change-has-occurr A quick fix would be creating an namespace App\EventSubscriber;
use DH\Auditor\Event\LifecycleEvent;
use JsonException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AuditSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
LifecycleEvent::class => 'onAuditEvent',
];
}
public function onAuditEvent(LifecycleEvent $event)
{
if (isset($event->getPayload()['entity'], $event->getPayload()['diffs'])) {
try {
$payload = $event->getPayload();
$diffs = json_decode($payload['diffs'], true, 512, JSON_THROW_ON_ERROR);
foreach ($diffs as $key => $values) {
if ((is_array($values) && array_key_exists('new', $values) && array_key_exists('old', $values))
&& (is_int($values['new']) || is_float($values['new']))
&& (is_string($values['old'])
&& ((float) $values['new']) === ((float) $values['old']))
) {
unset($diffs[$key]);
}
}
if (empty($diffs)) {
$event->stopPropagation();
}
$payload['diffs'] = json_encode($diffs, JSON_THROW_ON_ERROR);
$event->setPayload($payload);
} catch (JsonException $e) {
}
}
}
} |
This subscriber not working.. Always if diff is empty still log with bad values. If i changed it to something else, it log always something else. But can not get result log nothing |
auditor-bundle
versionSummary
I have an entity with a column of type decimal. When i save the entity, the values from the decimal type does diff even if they haven't changed because the comparison it not working properly.
It compares 60 with 60.00 from database and then it diffs. I'm using the Symfony MoneyType.
Any suggestion how to prevent this?
Current behavior
How to reproduce
Create a property with decimal type.
Try to use in any form.
Expected behavior
The diff should not be saved as the value is the same.
The text was updated successfully, but these errors were encountered: