AlgebraicJulia / ACSets.jl

ACSets: Algebraic databases as in-memory data structures
https://algebraicjulia.github.io/ACSets.jl/
MIT License
18 stars 8 forks source link

Serialization issue when using `missing` #108

Open slwu89 opened 7 months ago

slwu89 commented 7 months ago

The following round-trip serialization has an error when reading the data back in. The error is ERROR: MethodError: no method matching Union{Missing, String}(::String).

using Catlab

@present SimpleSch(FreeSchema) begin
    X::Ob
    Attr1::AttrType
    attr::Attr(X,Attr1)
end

@acset_type SimpleData(SimpleSch)

simple_data = @acset SimpleData{Union{String,Missing}} begin
    X=3
    attr=["a",missing,"c"]
end

write_json_acset_schema(SimpleSch, "./simplesch.json")
write_json_acset(simple_data, "./simpledata.json")

SimpleSch1 = read_json_acset_schema("./simplesch.json")

@acset_type SimpleData1(SimpleSch1)

simple_data1 = read_json_acset(SimpleData1{Union{String,Missing}}, "./simpledata.json")

On versions

  [227ef7b5] ACSets v0.2.13
  [134e5e36] Catlab v0.16.5
slwu89 commented 2 months ago

@olynch or @epatters do you have any ideas on how we could address this? The issue is when parsing the json acset we hit these methods in StructTypes https://github.com/JuliaData/StructTypes.jl/blob/main/src/StructTypes.jl#L524-L526 and it tries to call Union{String,Missing}(). Once again, union types being a source of strange behavior in Julia.