Opened 10 years ago

Closed 10 years ago

#13998 closed defect (fixed)

hash of a pickled Sequence is broken

Reported by: Sébastien Labbé Owned by: Sébastien Labbé
Priority: major Milestone: sage-5.7
Component: pickling Keywords:
Cc: Merged in: sage-5.7.beta2
Authors: Sébastien Labbé Reviewers: Stephan Ehlen
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Sébastien Labbé)

The following works::

    sage: M = ModularSymbols(1,12,sign=1)
    sage: M
    Modular Symbols space of dimension 2 for Gamma_0(1) of weight 12 with sign 1 over Rational Field
    sage: S = M.cuspidal_submodule().decomposition()[0].free_module().basis()
    sage: type(S)
    <class 'sage.structure.sequence.Sequence_generic'>
    sage: S
    [
    (1, 0)
    ]
    sage: hash(S)
    979268961

But if you do the same from a certain pickled object, it is broken (tested on sage-4.7 and sage-5.6.rc0)::

    sage: M = load('http://sage.math.washington.edu/home/slabbe/LMFDB/mstest.sobj')
    Attempting to load remote file: http://sage.math.washington.edu/home/slabbe/LMFDB/mstest.sobj
    Loading: [.]
    sage: M
    Modular Symbols space of dimension 2 for Gamma_0(1) of weight 12 with sign 1 over Rational Field
    sage: S = M.cuspidal_submodule().decomposition()[0].free_module().basis()
    sage: type(S)
    <class 'sage.structure.sequence.Sequence_generic'>
    sage: S
    [
    (1, 0)
    ]
    sage: hash(S)
    Traceback (most recent call last)
    ...
    AttributeError: 'Sequence_generic' object has no attribute '_Sequence_generic__hash'

This particular problem was reported by LMFDB developper who understands that Sage do not guarrenty that pickled object are supported by later version of Sage. Let's fix this problem !!!

Attachments (1)

trac_13998_unpickle_sequence-sl.patch (1.6 KB) - added by Sébastien Labbé 10 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by Sébastien Labbé

Here is a way to reproduce the problem on a recent version of Sage:

sage: S = Sequence([])
sage: S.set_immutable()
sage: del S._Sequence_generic__hash
sage: hash(S)
Traceback (most recent call last):
...
AttributeError: 'Sequence_generic' object has no attribute '_Sequence_generic__hash'
sage:
sage: S._Sequence__hash = 34  # providing this value should fix the above error but it doesn't:
sage: hash(S)
Traceback (most recent call last):
...
AttributeError: 'Sequence_generic' object has no attribute '_Sequence_generic__hash'

This is what I am going to use to doctest the fix.

Changed 10 years ago by Sébastien Labbé

comment:2 Changed 10 years ago by Sébastien Labbé

Status: newneeds_review

comment:3 Changed 10 years ago by Sébastien Labbé

Description: modified (diff)

comment:4 Changed 10 years ago by Stephan Ehlen

Status: needs_reviewpositive_review

I tested the patch with sage version 5.5.

I tested that:

  • The described bug does not occur anymore with the pickled object (see also my remark below).
  • The buggy behaviour described in comment 1 is now fixed.
  • The patch adds doctests for the patch with reference to the trac ticket.
  • The doctests complete without any errors.
  • The sage documentation builds fine.

Remark: In fact, the pickled object was provided by me and belongs to a large collection that serves the LMFDB (www.lmfdb.org) website currently. This means that the bug affected >13000 pickled objects. Now the first example from above works with the objects taken from the database (I tested a few, not all of them.)

Last edited 10 years ago by Stephan Ehlen (previous) (diff)

comment:5 Changed 10 years ago by Jeroen Demeyer

Please fill in the Author / Reviewer fields.

comment:6 Changed 10 years ago by Sébastien Labbé

Authors: Sébastien Labbé
Reviewers: Stephan Ehlen

comment:7 Changed 10 years ago by Jeroen Demeyer

Merged in: sage-5.7.beta2
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.