In a metaclass's __init__, the attributes have already been placed on the class, so mutating the attributes dict has no effect.
Try setting the id attribute directly: self.id = PrimaryKey(...) On Mar 27, 6:04 pm, Daniel Robbins <drobb...@funtoo.org> wrote: > Hi All, > > In 0.6_beta2, the following code is not properly adding a primary key Column > via DeclarativeMeta which calls my PrimaryKey() function: > > def PrimaryKey(seqprefix): > return Column(Integer, Sequence(seqprefix, optional=True), > primary_key=True) > > class ClassDefaults(DeclarativeMeta): > def __init__(cls,classname, bases, dict_): > seqprefix = getattr(cls,'__tablename__',None) > dict_['id'] = PrimaryKey(seqprefix=seqprefix) > return DeclarativeMeta.__init__(cls, classname, bases, dict_) > > Base = declarative_base(metaclass=ClassDefaults) > > class Location(Base): > __tablename__ = 'location' > parent_id = Column(Integer, ForeignKey('location.id')) > parent = relation('Location', backref=backref('children'), > remote_side='location.c.id') > name = UniqueString(25) > desc = Column(String(80)) > > SQLAlchemy 0.6_beta2 complains on table initialization: > > File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/mapper.py", line > 444, in _configure_pks > "key columns for mapped table '%s'" % (self, > self.mapped_table.description)) > sqlalchemy.exc.ArgumentError: Mapper Mapper|Location|location could not > assemble any primary key columns for mapped table 'location' > > This worked under 0.6_beta1 (and likely earlier versions of SQLAlchemy). > > Can someone send me some code similar to above that works with 0.6_beta2, or > is this a bug in beta2? > > Thanks, > > Daniel -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.