invenia / JLSO.jl

Julia Serialized Object (JLSO) file format for storing checkpoint data.
MIT License
90 stars 5 forks source link

Failing to serialize lambda function when using BSON #105

Open racinmat opened 3 years ago

racinmat commented 3 years ago

Lambda function fails to deserialize in JLSO 2.5.0 and BSON 0.3.3. Here is MWE

julia>         using JLSO
               a_fun = ()->nothing
               io = IOBuffer()
               JLSO.save(io, Dict(:a_fun=>a_fun), format=:bson; compression=:gzip)
               seek(io, 0)
               data_loaded = JLSO.load(io)
[warn | JLSO]: MethodError: no method matching BSON.__deserialized_types__.var"#15#16"()
Dict{Symbol,Any} with 1 entry:
  :a_fun => UInt8[0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a  …  0x7e, 0x03, 0x16, 0xdc, 0xd0, 0x72, 0xc2, 0x13, 0x00, 0x00]

persistence works, but loading not, and it loads lambda function only as bytes.

Using pure BSON, it works

julia>         using BSON
               io = IOBuffer()
               BSON.bson(io, Dict(:a_fun=>a_fun))
               seek(io, 0)
               data_loaded = BSON.load(io)
Dict{Symbol,Any} with 1 entry:
  :a_fun => #17

This bug is replicable also with JLSO versions 2.4, 2.3.3, 2.2 and BSON 0.2.6, 0.2.5.