JuliaIO / JLD2.jl

HDF5-compatible file format in pure Julia
Other
553 stars 88 forks source link

Deserializing LRUCache.LRU breaks in v0.4.37 #497

Closed justinmimbs closed 11 months ago

justinmimbs commented 11 months ago

I'm not sure if this is something that should be fixed in LRUCache or here. This works with v0.4.36.

using JLD2
using LRUCache: LRU

jldsave("lru.jld2"; lru = LRU{UInt64,String}())
jldopen(f -> f["lru"], "lru.jld2")

But it throws with v0.4.37.

ERROR: UndefKeywordError: keyword argument `maxsize` not assigned
Stacktrace:
  [1] LRU{UInt64, String}()
    @ LRUCache ~/.julia/packages/LRUCache/NCFtW/src/LRUCache.jl:21
JonasIsensee commented 11 months ago

Hi @justinmimbs, thanks for the report. The error message above has little to do with JLD2.

julia> LRU{UInt64, String}()
ERROR: UndefKeywordError: keyword argument `maxsize` not assigned
Stacktrace:
   [1] LRU{UInt64, String}()
     @ LRUCache /data.lmp/isensee/.julia/packages/LRUCache/NCFtW/src/LRUCache.jl:21

When I construct a cache with the required maxsize keyword, it works for me.

julia> jldsave("lru.jld2"; lru = LRU{UInt64,String}(maxsize=10))

julia> load("lru.jld2")
Dict{String, Any} with 1 entry:
  "lru" => LRU{UInt64, String}(; maxsize = 10)

If the problem persists, you are welcome to provide more info :)

justinmimbs commented 11 months ago

Thanks, @JonasIsensee.

I'm sorry, I stripped my example too aggressively when posting it. 😅

Running the corrected example using JLD2 v0.4.36 gives me the same result you posted. However, running it using JLD2 v0.4.37 gives me the error as described.

julia> jldsave("lru.jld2"; lru = LRU{UInt64,String}(maxsize=10))

julia> load("lru.jld2")
Error encountered while load FileIO.File{FileIO.DataFormat{:JLD2}, String}("lru.jld2").

Fatal error:
ERROR: UndefKeywordError: keyword argument `maxsize` not assigned
Stacktrace:
  [1] LRU{UInt64, String}()
    @ LRUCache ~/.julia/packages/LRUCache/NCFtW/src/LRUCache.jl:21
  [2] rconvert(#unused#::Type{LRU{UInt64, String}}, x::Vector{Pair{UInt64, String}})
    @ JLD2 ~/.julia/packages/JLD2/z2UM4/src/data/specialcased_types.jl:252
  [3] jlconvert(#unused#::JLD2.ReadRepresentation{LRU{UInt64, String}, JLD2.CustomSerialization{Array, JLD2.RelOffset}}, f::JLD2.JLDFile{JLD2.MmapIO}, ptr::Ptr{Nothing}, header_offset::JLD2.RelOffset)
    @ JLD2 ~/.julia/packages/JLD2/z2UM4/src/data/custom_serialization.jl:57
  [4] read_scalar(f::JLD2.JLDFile{JLD2.MmapIO}, rr::JLD2.ReadRepresentation{LRU{UInt64, String}, JLD2.CustomSerialization{Array, JLD2.RelOffset}}, header_offset::JLD2.RelOffset)
    @ JLD2 ~/.julia/packages/JLD2/z2UM4/src/dataio.jl:37
  [5] read_data(f::JLD2.JLDFile{JLD2.MmapIO}, rr::Any, read_dataspace::Tuple{JLD2.ReadDataspace, JLD2.RelOffset, JLD2.DataLayout, JLD2.FilterPipeline}, attributes::Vector{JLD2.ReadAttribute})
    @ JLD2 ~/.julia/packages/JLD2/z2UM4/src/datasets.jl:238

Can you please confirm this does not error for you using these versions?

  [033835bb] JLD2 v0.4.37
  [8ac3fa9e] LRUCache v1.5.0

Thanks for your help.

JonasIsensee commented 11 months ago

That makes more sense. Ah, maybe I only tested on an older version of JLD2.

This was broken by #492 which apparently was an overly eager fix.

It should not define a custom serialization for <:AbstractDict but only for the ones implementations of AbstractDict.

JonasIsensee commented 11 months ago

This is fixed on v0.4.38