Skip to content

Commit d3b44bf

Browse files
sdaultonmeta-codesync[bot]
authored andcommitted
fix GS serialization issue (#4984)
Summary: Pull Request resolved: #4984 `object_from_json` mutates its input dicts by popping `__type` keys during deserialization. In `generation_node_from_json`, `transition_criteria` and `generation_pausing_criteria` are decoded sequentially via `object_from_json`. Reviewed By: saitcakmak, Balandat Differential Revision: D95443476 fbshipit-source-id: 2d309d902ff6bff4cf5556227d39ceb7608ced21
1 parent f973cb4 commit d3b44bf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ax/storage/json_store/decoder.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# pyre-strict
88

9+
import copy
910
import datetime
1011
import json
1112
from collections import OrderedDict
@@ -934,13 +935,19 @@ def generation_node_from_json(
934935
class_decoder_registry=class_decoder_registry,
935936
),
936937
should_deduplicate=generation_node_json.pop("should_deduplicate", False),
938+
# Deep-copy criteria JSON before decoding. object_from_json mutates
939+
# its input dicts (pops "__type" keys). If the transport layer (e.g.
940+
# FBLearner/msgpack) returns data with shared dict objects between
941+
# transition_criteria and generation_pausing_criteria (e.g. shared
942+
# TrialStatus dicts), decoding one would strip "__type" from the other,
943+
# causing enums to be deserialized as plain dicts.
937944
transition_criteria=object_from_json(
938-
object_json=transition_criteria_json,
945+
object_json=copy.deepcopy(transition_criteria_json),
939946
decoder_registry=decoder_registry,
940947
class_decoder_registry=class_decoder_registry,
941948
),
942949
pausing_criteria=object_from_json(
943-
object_json=generation_pausing_criteria_json,
950+
object_json=copy.deepcopy(generation_pausing_criteria_json),
944951
decoder_registry=decoder_registry,
945952
class_decoder_registry=class_decoder_registry,
946953
),

0 commit comments

Comments
 (0)