On Jul 1, 2011, at 11:26 AM, Michael Bayer wrote: > > On Jul 1, 2011, at 5:10 AM, Arturo Sevilla wrote: > >> Hi, >> >> I've been trying on the new futures of composite classes of SQLAlchemy 0.7, >> and I don't have any problems with the read-only default mapping. However, >> just when I inherit from MutableComposite I start to get an AttributeError >> exception when I set the value to None (AttributeError: type object >> 'MutableComposite' has no attribute 'coerce' in /sqlalchemy/ext/mutable.py", >> line 386, in set). I am running SQLAlchemy version 0.7.1. My mapping and >> classes are the following: > > I've taken the extra steps to add imports plus an example usage to your > mapping, and can only reproduce that condition if I assign something that is > not a ContactInformation to "contact". That error should be improved, but > need to know if that is the problem on your end since those details were not > sent along.
that issue is fixed in r510553e87647 . The version at http://hg.sqlalchemy.org/sqlalchemy/archive/default.zip will have a more informative error message for your test case. > > > > from sqlalchemy import * > from sqlalchemy.orm import * > from sqlalchemy.ext.mutable import MutableComposite > > metadata = MetaData() > > class ContactInformation(MutableComposite): > > def __init__(self, *args, **kwargs): > props = ['home_page', 'phone', 'fax', 'nextel'] > if len(args) > 0: > for i in range(len(args)): > kwargs[props[i]] = args[i] > self.home_page = kwargs.get('home_page', None) > self.phone = kwargs.get('phone', None) > self.fax = kwargs.get('fax', None) > self.nextel = kwargs.get('nextel', None) > > def __composite_values__(self): > return self.home_page, self.phone, self.fax, self.nextel > > def __setattr__(self, name, value): > object.__setattr__(self, name, value) > # the following line gets uncommented when changed to MutableComposite > #self.changed() > > def __eq__(self, other): > return other is not None and \ > str(self.home_page) == str(other.home_page) and \ > self.phone == other.phone and \ > self.fax == other.fax and \ > self.nextel == other.nextel > > def __ne__(self, other): > return not self.__eq__(other) > > user = Table( > 'User', > metadata, > Column('ID', Integer, primary_key=True), > Column('HomePage', String(300), nullable=True), > Column('Telephone', String(30), nullable=True), > Column('Fax', String(30), nullable=True), > Column('Nextel', String(30), nullable=True) > ) > > class User(object): > def __init__(self, contact): > self.contact = contact > > mapper(User, user, properties={ > 'id': user.c.ID, > 'contact': composite(ContactInformation, user.c.HomePage, > user.c.Telephone, user.c.Fax, user.c.Nextel), > }) > > e = create_engine('sqlite://') > metadata.create_all(e) > > s = Session(e) > > u = User( > ContactInformation(home_page='asdf', phone='asdf', fax='asfd', > nextel='asdf') > ) > > > u.contact.phone = 'asdfas' > > s.add(u) > s.commit() > > u = s.query(User).first() > u.contact.home_page='asdfdasf' > s.commit() > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.