-
Notifications
You must be signed in to change notification settings - Fork 3
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
Unstable hashes in Pluto.jl notebooks #41
Comments
Hey there, sorry I've been slow to take a look at this. Had some tight deadlines before the holiday's and am just looking at this upon my return from vacation.
I agree. It should be possible to check for this case and print a warning for the user, along with some advice for how to avoid it. I would be wary of your fix: StableHashTraits.qualified_name_(x::T) where {T} = let
str = StableHashTraits.qname_(T <: DataType ? x : T, nameof)
stable_pluto_workspace_name(str)
end
StableHashTraits.qualified_type_(x::T) where {T} = let
str = StableHashTraits.qname_(T <: DataType ? x : T, string)
stable_pluto_workspace_name(str)
end There are some weird things that can happen when redefining a function that is called inside of a I think a better work around would be define this right after defining your type: StableHashTraits.hash_method(::MyType) = @ConstantHash("Pluto.MyType"), StructHash() That should ensure that the type tag for your type is constant. It might even be possible to automated this: e.g. if I can verify that the module was created from a Pluto cell somehow. |
I like your |
Thanks for having a look. So I guess the easiest solution would be to warn/error by default and tell the user about a workaround along the lines you suggested, i.e. StableHashTraits.hash_method(::MyType) = @ConstantHash("Pluto.MyType"), StructHash() I agree that doing better probably requires cooperation from Pluto.jl in some form. cc @fonsp who might have some thoughts? |
@Pangoraw understands this better! I'm up for implementing a method Though I would say that the |
Cool! I like the long-term solution of adding a function to |
I've been trying to use
StableHashTraits
in aPluto.jl
notebook, like this:But that is not a good idea because the hash is not actually stable. For example, suppose I want to add a comment to the definition of
MyStruct
. To do this, I add the comment and then re-evaluate the cell. The hash is now different although the definition ofMyStruct
hasn't changed, like this:I think the reason is that
parentmodule(MyStruct)
is not stable (see the screenshots) but enters the hash:StableHashTraits.jl/src/StableHashTraits.jl
Line 437 in 1447160
I'm not sure how to best deal with this, but I think it is a major footgun for Pluto users so something should be done. It might be good enough to just detect this case and warn or throw an error? Like what seems to be done for other types here:
StableHashTraits.jl/src/StableHashTraits.jl
Lines 430 to 435 in 1447160
Then Pluto users are aware of the issue and can try to work around it.
Fwiw, adding the following code to Pluto notebooks seems to work fine for me. But that's just an ugly hack. Do you know of a better way? Do you think something should be changed on the Pluto side?
Edit: Probably related: fonsp/Pluto.jl#1030 . I guess the problem here is more on the Pluto side. Still, I think it would be good to adjust
validate_name
to disallow types defined in Pluto by default. And maybe there could be a (nicer) way for Pluto users to hook intoStableHashTraits
to work around the problem?The text was updated successfully, but these errors were encountered: