Hi I am having a problem when i run the code below, it gives me the following error:
Traceback (most recent call last): File "./alch.py", line 45, in <module> f.add(datetime.now(), 1.0) File "./alch.py", line 17, in add self.vals[key] = value File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/ collections.py", line 1048, in __setitem__ value = __set(self, value, _sa_initiator) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/ collections.py", line 885, in __set item = getattr(executor, 'fire_append_event')(item, _sa_initiator) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/ collections.py", line 582, in fire_append_event return self.attr.fire_append_event(self.owner_state, self.owner_state.dict, item, initiator) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/ attributes.py", line 665, in fire_append_event self.sethasparent(instance_state(value), True) AttributeError: 'float' object has no attribute '_sa_instance_state' The code is just an example showing the issue, the real code is doing more. Effectively, i have a class (Foo) that contains a dict, which i'm using to store some key/value pairs. The container class (Vals) has inherited from dict because I need a class when i create the relation in Foo. I have a feeling I'm missing something simple but haven't yet worked out what. Thanks #!/usr/bin/env python2.6 from sqlalchemy import * from sqlalchemy.orm import sessionmaker, mapper, relation from sqlalchemy.orm.collections import column_mapped_collection from datetime import datetime class Vals(dict): pass class Foo(object): def __init__(self, name): self.vals = Vals() self.name = name def add(self, key, value): self.vals[key] = value engine = create_engine('sqlite:///:memory:', echo=True) meta = MetaData(bind=engine) Session = sessionmaker(bind=engine) vals = Table('vals', meta, Column('id', Integer, primary_key=True), Column('date', DateTime), Column('val', Integer), Column('foo_id', Integer, ForeignKey('foo.id')) ) mapper(Vals, vals) foo = Table('foo', meta, Column('id', Integer, primary_key=True), Column('name', String(50)) ) mapper(Foo, foo, properties = dict( vals = relation(Vals, collection_class = column_mapped_collection (vals.c.date)) )) sess = Session() meta.create_all() f = Foo('hello') f.add(datetime.now(), 1.0) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---