Page MenuHomePhabricator

JsonCodec should be robust against class aliases
Closed, ResolvedPublic

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

Change #1026191 merged by jenkins-bot:

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

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

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

[mediawiki/vendor@master] Bump wikimedia/json-codec to 2.2.3

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

Change #1041121 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/json-codec to 3.0.1

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

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

[mediawiki/core@master] [JsonCodec] Use wikimedia/json-codec to implement JsonCodec

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

Change #1026184 abandoned by C. Scott Ananian:

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

Reason:

Squashed in Ia1017dcef462f3ac1ff5112106f7df81f5cc384f.

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

Change #1038445 merged by jenkins-bot:

[mediawiki/core@master] [JsonCodec] Use wikimedia/json-codec to implement JsonCodec

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