Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading old data that contains anonymous methods fails with BSON.jl v0.3.3 #95

Open
takasho777 opened this issue Apr 9, 2021 · 3 comments

Comments

@takasho777
Copy link

With #94, I can save and load data that have anonymous methods in Julia 1.6. However, when I load such a BSON file that's saved with the previous version of Julia and BSON.jl, then BSON.load method fails. Is there a workaround to this compatibility issue? Below is an example borrowed from #80.

With Julia 1.5.4 and BSON.jl v0.3.2

using BSON
f = x -> 2x
BSON.@save "test.bson" f

Then, with Julia 1.6.0 and BSON.jl v0.3.3

using BSON
BSON.load("test.bson")

which returns the following error.

ERROR: MethodError: Cannot `convert` an object of type Module to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
  Symbol(::Any...) at strings/basic.jl:229
Stacktrace:
  [1] newstruct!(::Method, ::Module, ::Symbol, ::Symbol, ::Int32, ::Type, ::String, ::Nothing, ::Int32, ::Bool, ::Int32, ::Core.CodeInfo)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/extensions.jl:99
  [2] newstruct_raw(cache::IdDict{Any, Any}, T::Type, d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/extensions.jl:126
  [3] (::BSON.var"#45#46")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/extensions.jl:141
  [4] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:92
  [5] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:98
  [6] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/BSON.jl:28
  [7] raise_recursive
    @ ~/.julia/packages/BSON/aEqHo/src/read.jl:98 [inlined]
  [8] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:98
  [9] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/BSON.jl:28
 [10] raise_recursive(v::Vector{Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:98
 [11] newstruct_raw(cache::IdDict{Any, Any}, #unused#::Type{Core.TypeName}, d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/anonymous.jl:95
 [12] (::BSON.var"#45#46")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/extensions.jl:141
 [13] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:92
 [14] (::BSON.var"#18#21"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:82
 [15] applychildren!(f::BSON.var"#18#21"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/BSON.jl:21
 [16] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:82
 [17] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:93
 [18] (::BSON.var"#45#46")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/extensions.jl:139
 [19] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:92
 [20] (::BSON.var"#19#22"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:86
 [21] applychildren!(f::BSON.var"#19#22"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/aEqHo/src/BSON.jl:21
 [22] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:86
 [23] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/aEqHo/src/read.jl:93
 [24] raise_recursive
    @ ~/.julia/packages/BSON/aEqHo/src/read.jl:103 [inlined]
 [25] load (repeats 2 times)
    @ ~/.julia/packages/BSON/aEqHo/src/read.jl:108 [inlined]
 [26] top-level scope
    @ REPL[3]:1
@bienpierre
Copy link

Hello,
I have the same issue. Have you found a workaround?
Regards

@darsnack
Copy link
Contributor

You can use #102 as a quick workaround. The reason we haven't merged yet is because the fix involves updating some fragile code calling into Julia's C internals. So, we are doing a longer term fix that removes that fragile implementation entirely. But #102 will work in a pinch.

@darsnack
Copy link
Contributor

I am closing this as a duplicate of #107.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants