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

Broken unpickling of nested bindable classes in corner case #25491

Open
nthiery opened this issue Jun 1, 2018 · 3 comments
Open

Broken unpickling of nested bindable classes in corner case #25491

nthiery opened this issue Jun 1, 2018 · 3 comments

Comments

@nthiery
Copy link
Contributor

nthiery commented Jun 1, 2018

Classes are pickled by name in Sage, and reconstructed as in this example upon unpickling:

sage: cls = unpickle_global('sage.categories.hopf_algebras_with_basis', 'HopfAlgebrasWithBasis.TensorProducts')

In practice, unpickle_global loads the module, and search for the full class name HopfAlgebrasWithBasis.TensorProducts in the dictionary of the module.

In the case of a nested class above which comes from a functorial construction, there currently are cases where, upon importing the module, the base class of the nested class has not yet been initialized, which leads to errors:

sage: cls(QQ)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
...
KeyError: 'HopfAlgebrasWithBasis.'

The initialization is indeed done upon accessing the class for the first time from its surrounding class:

    sage: HopfAlgebrasWithBasis.TensorProducts

Now everything works:

sage: cls is HopfAlgebrasWithBasis.TensorProducts
True
sage: cls(QQ)
Category of tensor products of hopf algebras with basis over Rational Field

Not sure what's the best way to proceed; forcing the unpickling
to unpickle instead the base class HopfAlgebrasWithBasis, and then recover TensorProducts by a getattr ?

I'll add the original non-working example that was found by Pauline.

Component: pickling

Issue created by migration from https://trac.sagemath.org/ticket/25491

@nthiery nthiery added this to the sage-8.3 milestone Jun 1, 2018
@nthiery
Copy link
Contributor Author

nthiery commented Jun 3, 2019

comment:1

Hmm, got hurt by this once again ... in a variant of the same use case.

@nthiery
Copy link
Contributor Author

nthiery commented Jun 3, 2019

comment:2

After poking around a bit, I'd be tempted to customize the pickling so that a nested class foo.A.B would be unpickled as getattr(getattr(foo, "A"),"B"). This would however not resolve the unpickling of old pickles.

@nthiery

This comment has been minimized.

@mkoeppe mkoeppe removed this from the sage-8.3 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants