I'm having trouble unpickling model instances where the class has an 
attribute-mapped collection:

import pickle

from sqlalchemy import create_engine, Column, Integer, Unicode, ForeignKey
from sqlalchemy.orm import Session, relationship
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
engine = create_engine('sqlite:///')
session = Session(engine)

class Parent(Base):
    __tablename__ = 'parents'
    id = Column(Integer, primary_key=True)
    
    children = relationship('Child', cascade='all, delete-orphan', 
lazy='subquery', collection_class=attribute_mapped_collection('key'))

class Child(Base):
    __tablename__ = 'children'
    parent_id = Column(Integer, ForeignKey(Parent.id), primary_key=True)
    key = Column(Integer, primary_key=True)
    value = Column(Unicode)

Base.metadata.create_all(engine)
parent = Parent()
session.add(parent)
session.flush()
session.refresh(parent)
pickled = pickle.dumps(parent, 2)
pickle.loads(pickled)


Executing this results in:

Traceback (most recent call last):
  File "sqlatest.py", line 32, in <module>
    pickle.loads(pickled)
  File "/usr/lib/python2.7/pickle.py", line 1382, in loads
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1083, in load_newobj
    obj = cls.__new__(cls, *args)
TypeError: attrgetter expected 1 arguments, got 0


If I remove the relationship, pickling and unpickling work fine. None of 
the other mapped collection variants work either, though they produce 
different tracebacks. Is this a bug or am I doing something wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/4yfUPzrOZXcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to