Commit c6a1770
Centralize experiment property serialization for JSON storage (#5113)
Summary:
Pull Request resolved: #5113
`update_properties_on_experiment` writes `experiment._properties` directly to the DB via raw `json.dumps`, bypassing the `experiment_to_sqa` encoder that converts non-JSON-serializable objects (like `LLMMessage` dataclasses) to plain dicts. This causes `TypeError: Object of type LLMMessage is not JSON serializable` for any experiment with LLM messages saved through the incremental property update path.
This diff extracts the property preparation logic into a shared `prepare_experiment_properties_for_storage` function called from both `experiment_to_sqa` and `update_properties_on_experiment`, ensuring all save paths use consistent serialization.
We considered adding a blanket `default=dataclasses.asdict` handler to the `JSONEncodedObject` TypeDecorator, but rejected it because: (1) dataclasses with non-JSON fields (e.g. `BenchmarkTrialMetadata` with `pd.DataFrame`) would produce confusing partial-conversion errors, (2) silently serializing dataclasses without paired decoders breaks round-trip fidelity, and (3) it removes the fail-fast guardrail for unexpected objects in JSON columns.
Differential Revision: D98828500
fbshipit-source-id: ed458af8647d30ac018e885e00a3466daeec61041 parent 8ec8faa commit c6a1770
3 files changed
Lines changed: 59 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
91 | 116 | | |
92 | 117 | | |
93 | 118 | | |
| |||
230 | 255 | | |
231 | 256 | | |
232 | 257 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
| 258 | + | |
245 | 259 | | |
246 | 260 | | |
247 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
540 | 543 | | |
541 | 544 | | |
542 | 545 | | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
543 | 550 | | |
544 | 551 | | |
545 | 552 | | |
546 | | - | |
| 553 | + | |
547 | 554 | | |
548 | 555 | | |
549 | 556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
2863 | 2864 | | |
2864 | 2865 | | |
2865 | 2866 | | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
2866 | 2890 | | |
2867 | 2891 | | |
2868 | 2892 | | |
| |||
0 commit comments