mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Field with type float and orm type decimal is wrongly detected as changed on update #6794
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @vlud on GitHub (Jul 27, 2021).
Bug Report
Summary
Fields with declared type float (php 7.4+) and doctrine orm type decimal are detected as changed on PreUpdate event .
Current behavior
My entity has a field of type float, which is declared as such (php 7.4). This same field has a decimal doctrine orm type.
Problem occurs when existing entity gets persisted, but with no new changes. In concrete application, this happens when this entity is relation of some other entity that does get updated. This leads application to think update happened and update event is triggered, with following changeset logged (var_dump($args->getEntityChangeSet()))
How to reproduce
Please checkout following code: https://github.com/vlud/doctrine-orm-float-issue-demo and follow steps defined in ReadMe to reproduce issue.
Note, that issue occurs on entity named
BookingWithFloatDecimal, and other entities are behaving as expected.Expected behavior
PreUpdate should not be triggered when no changes are performed on entity that has field of type float and orm type of decimal. If type is omitted, event is not triggered.
@mbabker commented on GitHub (Jul 27, 2021):
This has to do with how the two decimal field types (decimal and float) in the DBAL are handled (see https://www.doctrine-project.org/projects/doctrine-dbal/en/2.13/reference/types.html#decimal-types) and how the UoW detects changes.
The best way to deal with this when using a decimal type is to store the decimal value as a string in your entity class property (since that will match up with how
DecimalTypehandles conversions in the DBAL) and have your getter and setter handle type conversions so your application is working with floats but the ORM is tracking strings. Something like this would do the trick:@vlud commented on GitHub (Jul 28, 2021):
Thank you for the advice, @mbabker :) We ended up using different workaround - simply not defining this particular field as float. It works in our particular case.
@beberlei commented on GitHub (Aug 4, 2021):
Closing as its not a bug, but just related to the float/decimal specifics in PHP vs DBAL vs DBs