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

Spring items break pickling with Traits 5.0.0 #514

Closed
FedeMiorelli opened this issue Mar 11, 2019 · 7 comments · Fixed by #515
Closed

Spring items break pickling with Traits 5.0.0 #514

FedeMiorelli opened this issue Mar 11, 2019 · 7 comments · Fixed by #515

Comments

@FedeMiorelli
Copy link
Contributor

I encountered a strange behaviour while pickling traits with Traits 5.0.0 and Traitsui 6.0.0

If one trait contains an instance of another trait, whose view contains a Spring item, pickling results in an error.

In the following code, if one comments out the spring item in the view of the MyTrait the code works correctly, otherwise results in an error.

Most likely related to: enthought/traits#447



import pickle

from traits.api import HasStrictTraits, Str, Instance
from traitsui.api import View, Group, Item, InstanceEditor, spring

class MyTrait(HasStrictTraits):
    MyString = Str
    
    traits_view = View(Group(Item('MyString'), spring))   # If spring is removed, this code runs OK


class MySecondTrait(HasStrictTraits):
    MyFirst = Instance(MyTrait)
    
    
    def save(self):
        with open('test.dump', 'wb') as fid:
            st = self.__getstate__()
            pickle.dump(st, fid, protocol=2)
        
    def load(self):
        with open('test.dump', 'rb') as fid:
            self.__setstate__(pickle.load(fid))
        
    
    traits_view = View(Group(Item('MyFirst', editor=InstanceEditor(editable=True), style='custom'), show_labels=False), buttons=['OK'])
    
    
m0 = MyTrait(MyString='test')
m1 = MySecondTrait(MyFirst=m0)

m1.configure_traits()
m1.save()


m2 = MySecondTrait()
m2.load()
print(m2.MyFirst.MyString)

Expected output:

test

Error


Traceback (most recent call last):
  File "D:\Temp\testpickle.py", line 46, in <module>
    m1.save()
  File "D:\Temp\testpickle.py", line 31, in save
    pickle.dump(st, fid, protocol=2)
_pickle.PicklingError: Can't pickle <class 'traits.trait_types.Disallow'>: it's not the same object as traits.trait_types.Disallow
@corranwebster
Copy link
Contributor

Hi, thanks for the report. This looks like it is related to enthought/traits#452

The immediate workaround would be to downgrade your version of Traits to 4.6.0 (or github master prior to 23rd Dec 2018/commit eecc23d6 if there are bugfixes you need).

@corranwebster
Copy link
Contributor

I'm going to tentatively close the issue for now, since it is a duplicate of
enthought/traits#452 but please feel free to re-open if you think that the two issues are unrelated.

@FedeMiorelli
Copy link
Contributor Author

Forgot to mention I am running Python 3.7.1 on Windows 10 64bit.
Not sure if this warrants re-opening as the other issue refers to Python 2 explicitly?

Thank you

@corranwebster
Copy link
Contributor

If you still see the issue with Traits 4.6.0 please re-open the ticket. If not, maybe add your observations to the traits issue as an extra data point.

@mdickinson
Copy link
Member

Hmm. On closer inspection, this does look like a new variant of enthought/traits#452. It's not clear to me whether it should be a separate issue or not.

@FedeMiorelli
Copy link
Contributor Author

The issue is not present with v4.6.0, it appeared after update to 5.0.0

I leave up to you whether you'd like to re-open this or merge it with enthought/traits#452

Thanks!

@mdickinson
Copy link
Member

mdickinson commented Mar 11, 2019

So it's almost certainly a Traits issue rather than a Traits UI one - let's leave it closed here. I'll try to find time to investigate on the Traits side soon, and if necessary I'll split enthought/traits#452 into two issues then.

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants