Page MenuHomePhabricator

JsonCodec should be robust against class aliases
Open, Needs TriagePublic

Description

We do string-equality checks against class name, both in core's JsonCodec as well as in the json-codec library. This breaks when we move classes and use class_alias for compatibility. We should instead (a) switch to an equality test that takes aliases into account, and/or (b) document the proper procedure to use when making a change to a serialized class -- ie, do you need to add support to a special "other aliases" table in advance in order to allow rollbacks to work, or else put the class name in "other aliases" in the first train where the name switch happens so that you continue to use the 'old' name for a train or two?

Should also add support to the serialization test infrastructure to verify that aliases work. Maybe this would catch breaking aliases before they enter production.

Event Timeline

Two thoughts from slack:

Maybe is_a would work? If is_a($b, $a) && is_a($a, $b) is true that ought to be an equality check that is robust against aliases? One hopes?

and

You can apparently check the real class of an alias https://www.php.net/manual/en/class.reflectionclass.php#112212

Change #1026184 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] [JsonCodec] Better support class aliases

https://gerrit.wikimedia.org/r/1026184

Change #1026191 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/libs/JsonCodec@main] Ensure class hints work correctly even when class_alias is used

https://gerrit.wikimedia.org/r/1026191