mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
MySQL 5.7 JSON ordering affects change computation #5948
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 @MisatoTremor on GitHub (Apr 10, 2018).
Originally assigned to: @Ocramius on GitHub.
This is not really an issue with ORM itself, but can happen in conjunction with DBAL and MySQL 5.7s JSON type
If you store an associative array as a object property which, due to processing, is always ordered before persisting (e.g.
["baz" => "bar", "foo" => "bar"]) it will be correctly processed byJsonType::convertToDatabaseValueinto{"baz": "bar", "foo": "bar"}But due to MySQLs JSON normalization might end up in the database as
{"foo": "bar", "baz": "bar"}.So when hydrating the object the UOW will store this as value in the original entity data and when computing changes later will detect it as change.
@Ocramius commented on GitHub (Apr 10, 2018):
This could probably be fixed by enforcing order in the DBAL type, but again, the JSON spec does not enforce any order.
The in-memory objects are PHP arrays coming from a simple
json_decode()@MisatoTremor commented on GitHub (Apr 10, 2018):
Sorry @Ocramius, just completed the description as I inadvertently posted the issue before finishing the text.
@Ocramius commented on GitHub (Apr 10, 2018):
@MisatoTremor regardless about what MySQL does, we can't change anything on our side, because we'd destroy behavior that users might be relying upon.
The JSON type can sort keys before serializing, but that would be troublesome too.
If the only side-effect here is a repeated
UPDATEquery, then I'd rather leave this as a known issue (compared to introducing more awkwardness in JSON handling)@MisatoTremor commented on GitHub (Apr 10, 2018):
Yes, I thought so. My line of thinking was also that this could be noted in the docs where appropriate.
@Ocramius commented on GitHub (Apr 10, 2018):
@MisatoTremor that would make a lot of sense. That affects also affects the
objectandsimple_arraytypes. The file to edit is probably03c0797f03/docs/en/reference/types.rst@MisatoTremor commented on GitHub (Apr 10, 2018):
Thanks for the hads up @Ocramius. Shouldn't that just affect
jsonand the (deprecated)json_arraytypes as the other two use the CLOB declaration or am I overlooking something there?@Ocramius commented on GitHub (Apr 10, 2018):
@MisatoTremor anything that the DB may manipulate/optimise after persistence.