Skip to content

Cannot serialize during __init__ #56916

@willow-ahrens

Description

@willow-ahrens

On Version 1.11.2, serialization during __init__ results in a KeyError. Consider the following package:

module Foo

using Serialization

struct Bar
    x::Int
end

function __init__()
    mktemp() do path, io
        serialize(io, Bar(42))
    end
end

end # module Foo

Running using Foo results in:

ERROR: InitError: KeyError: key Foo not found
Stacktrace:
  [1] getindex
    @ ./iddict.jl:98 [inlined]
  [2] macro expansion
    @ ./lock.jl:273 [inlined]
  [3] root_module_key
    @ ./loading.jl:2420
  [4] serialize_mod_names
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:390
  [5] serialize
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:402 [inlined]
  [6] serialize_type_data
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:595
  [7] serialize_type
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:627
  [8] serialize_any
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:0
  [9] serialize
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:680 [inlined]
 [10] serialize
    @ ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/Serialization/src/Serialization.jl:807 [inlined]
 [11] #1
    @ ~/Projects/Foo/src/Foo.jl:11 [inlined]
 [12] mktemp
    @ ./file.jl:790
 [13] mktemp
    @ ./file.jl:788 [inlined]
 [14] __init__()
    @ Foo ~/Projects/Foo/src/Foo.jl:10
 [15] run_module_init(mod::Module, i::Int64)
    @ Base ./loading.jl:1378
 [16] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1366
 [17] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any}, ignore_native::Nothing; register::Bool)
    @ Base ./loading.jl:1254
 [18] _include_from_serialized (repeats 2 times)
    @ ./loading.jl:1210 [inlined]
 [19] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128, stalecheck::Bool; reasons::Dict{String, Int64}, DEPOT_PATH::Vector{String})
    @ Base ./loading.jl:2057
 [20] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2527
 [21] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2388
 [22] #invoke_in_world#3
    @ ./essentials.jl:1089 [inlined]
 [23] invoke_in_world
    @ ./essentials.jl:1086 [inlined]
 [24] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2375
 [25] macro expansion
    @ ./loading.jl:2314 [inlined]
 [26] macro expansion
    @ ./lock.jl:273 [inlined]
 [27] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2271
 [28] #invoke_in_world#3
    @ ./essentials.jl:1089 [inlined]
 [29] invoke_in_world
    @ ./essentials.jl:1086 [inlined]
 [30] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2260
during initialization of module Foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorfixed on masterpackagesPackage management and loadingregression 1.11Regression in the 1.11 releasestdlibJulia's standard library

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions