serde: Handle unicode issues when encoding

- any invalid utf-8 chars now removed on dumps
- fix serialization of Send
- remove serialization of NamedTuple, which doesn't work
- add test for custom serde passed to memory saver
- add test using Send and JsonPlus serde
This commit is contained in:
Nuno Campos
2024-06-03 16:28:32 -07:00
parent 8d54b09371
commit d22fe60d4c
5 changed files with 63 additions and 13 deletions
+6 -3
View File
@@ -43,9 +43,12 @@ class MemorySaverAssertImmutable(MemorySaver):
# assert checkpoint hasn't been modified since last written
thread_id = config["configurable"]["thread_id"]
if saved := super().get(config):
assert self.storage_for_copies[thread_id][saved["id"]] == saved
self.storage_for_copies[thread_id][checkpoint["id"]] = copy_checkpoint(
checkpoint
assert (
self.serde.loads(self.storage_for_copies[thread_id][saved["id"]])
== saved
)
self.storage_for_copies[thread_id][checkpoint["id"]] = self.serde.dumps(
copy_checkpoint(checkpoint)
)
# call super to write checkpoint
return super().put(config, checkpoint, metadata)