Fix BSON load error by saving timestamp as string#31
Conversation
To resolve errors where BSON doesn't manage to reconstruct the DateTime.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #31 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 57 57
=========================================
Hits 57 57 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
In particular, observed the following behavior on CacheVariables v0.2.0: (jl_gaMG15) pkg> st
Status `/private/var/folders/h_/3320nshd7t1bzbtcrj023bkr0000gn/T/jl_gaMG15/Project.toml`
[9a355d7c] CacheVariables v0.2.0
julia> using CacheVariables
julia> cache("test.bson") do
a = "a very time-consuming quantity to compute"
b = "a very long simulation to run"
return (; a = a, b = b)
end
┌ Info: Saved cached values to test.bson.
│ Run Timestamp : 2026-01-19T14:59:26.331 UTC (run took 0.003582958 sec)
└ Julia Version : 1.12.4
(a = "a very time-consuming quantity to compute", b = "a very long simulation to run")
julia> cache("test.bson") do
a = "a very time-consuming quantity to compute"
b = "a very long simulation to run"
return (; a = a, b = b)
end
ERROR: UndefVarError: `Dates` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: Dates is loaded but not imported in the active module Main.
Stacktrace:
[...]Related to: #28 I think the issue here may be that Anyway, the simple fix is probably to just store the date as a string in BSON. |
|
Notably, JLD2 seems to work fine! So, no need to switch to strings for that one. julia> cache("test.jld2") do
a = "a very time-consuming quantity to compute"
b = "a very long simulation to run"
return (; a = a, b = b)
end
┌ Info: Saved cached values to test.jld2.
│ Run Timestamp : 2026-01-19T15:04:01.087 UTC (run took 0.007473458 sec)
└ Julia Version : 1.12.4
(a = "a very time-consuming quantity to compute", b = "a very long simulation to run")
julia> cache("test.jld2") do
a = "a very time-consuming quantity to compute"
b = "a very long simulation to run"
return (; a = a, b = b)
end
┌ Info: Loaded cached values from test.jld2.
│ Run Timestamp : 2026-01-19T15:04:01.087 UTC (run took 0.007473458 sec)
└ Julia Version : 1.12.4
(a = "a very time-consuming quantity to compute", b = "a very long simulation to run")Once I've gotten to play around with JLD2 to get some more confidence in it, I think we should probably switch all the examples to use that (i.e., encourage that as the default rather than BSON). |
To resolve errors where BSON doesn't manage to reconstruct the DateTime.