Commit 2df2b20
Fix custom serialization gaps from #154
Close several round-tripping gaps left by the type-aware custom
serialization work in #154, without introducing new breaking changes
versus 1.5.0 or any serialization-related security concerns.
Serialize side:
- Prefer a to_json() hook over the built-in dataclass / SimpleNamespace
handling so a dataclass (or namespace) with a non-serializable field can
opt in, mirroring the decode side which already prefers from_json().
- Encode dataclasses via a shallow field mapping instead of
dataclasses.asdict(), so nested to_json() hooks are honored and leaf
values are not deep-copied.
- Serialize enum.Enum values to their underlying .value so non-int enums
round-trip (IntEnum already serialized as integers).
Deserialize side:
- Recurse type-directed reconstruction into dict/Mapping values and tuple
elements, in addition to the existing list / Optional / Union / dataclass
recursion.
- Optionally pass the active DataConverter to a from_json(cls, value,
converter) hook so it can rebuild nested typed values the built-in
recursion does not cover.
Entity state:
- Defer deserialization of an entity's wire state until get_state() is
called, so the caller's requested type reaches the converter together
with the raw payload. Track whether the held value is still the raw
serialized string and pass it back through unchanged on persist to avoid
double-encoding.
- Replace a redundant serialize/deserialize round-trip in the legacy entity
event path with converter.coerce().
Module structure / deprecation:
- Merge the internal json_codec module into durabletask.serialization and
make the codec functions private; the supported surface is the pluggable
DataConverter.
- Deprecate durabletask.internal.shared.to_json / from_json with a
DeprecationWarning; they continue to work for backwards compatibility.
Adds a comprehensive JsonDataConverter round-trip test suite plus targeted
tests for each fix, and documents intentional limitations (multi-member
Union, types needing a custom converter such as datetime/Decimal/set).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 532479d commit 2df2b20
10 files changed
Lines changed: 1446 additions & 275 deletions
File tree
- durabletask
- internal
- tests/durabletask
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
40 | 49 | | |
41 | 50 | | |
42 | 51 | | |
| |||
63 | 72 | | |
64 | 73 | | |
65 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
66 | 91 | | |
67 | 92 | | |
68 | 93 | | |
69 | 94 | | |
70 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
71 | 104 | | |
72 | 105 | | |
73 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
16 | 36 | | |
| 37 | + | |
17 | 38 | | |
| 39 | + | |
18 | 40 | | |
19 | 41 | | |
20 | 42 | | |
| |||
35 | 57 | | |
36 | 58 | | |
37 | 59 | | |
38 | | - | |
| 60 | + | |
39 | 61 | | |
40 | 62 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
45 | 73 | | |
46 | 74 | | |
47 | 75 | | |
48 | 76 | | |
49 | 77 | | |
50 | 78 | | |
51 | 79 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 80 | + | |
| 81 | + | |
55 | 82 | | |
56 | 83 | | |
57 | 84 | | |
58 | 85 | | |
59 | | - | |
| 86 | + | |
60 | 87 | | |
61 | 88 | | |
| 89 | + | |
62 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
63 | 107 | | |
64 | 108 | | |
65 | 109 | | |
| |||
69 | 113 | | |
70 | 114 | | |
71 | 115 | | |
| 116 | + | |
72 | 117 | | |
73 | 118 | | |
74 | 119 | | |
75 | 120 | | |
| 121 | + | |
76 | 122 | | |
77 | 123 | | |
78 | 124 | | |
79 | 125 | | |
| 126 | + | |
80 | 127 | | |
| 128 | + | |
81 | 129 | | |
82 | 130 | | |
This file was deleted.
0 commit comments