I'm trying to fix/finish a half-broken dialect for OpenBase that was handed to me. I haven't gotten so far as using the SQLAlchemy test suite yet (OpenBase makes unit testing hard because a sequence of Create/drop messages deadlocks the db server, which is what tests normally do in setUp and tearDown), but I've written a simple script based on the SQLAlchemy ORM tutorial:
metadata = MetaData(bind=engine) users_table = Table('testusers', metadata, Column('_rowid', Integer, primary_key=True), Column('name', String(50))) metadata.create_all(engine) class User(object): pass mapper(User, users_table) ed = User() ed.name = "Ed" print("Eds id after creation: %s" % ed._rowid) Session = sessionmaker(bind=engine) session = Session() session.add(ed) session.commit() print("Eds id after commit: %s" % ed._rowid) If I run this code I get this error: Traceback (most recent call last): File "alchtest.py", line 46, in <module> print("Eds id after commit: %s" % ed._rowid) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.5.0rc4- py2.5.egg/sqlalchemy/orm/attributes.py", line 150, in __get__ return self.impl.get(instance_state(instance)) File "/Library/Python/2.5/site-packages/SQLAlchemy-0.5.0rc4- py2.5.egg/sqlalchemy/orm/attributes.py", line 345, in get value = callable_() File "/Library/Python/2.5/site-packages/SQLAlchemy-0.5.0rc4- py2.5.egg/sqlalchemy/orm/attributes.py", line 949, in __call__ attr.impl.key in unmodified File "/Library/Python/2.5/site-packages/SQLAlchemy-0.5.0rc4- py2.5.egg/sqlalchemy/orm/mapper.py", line 1772, in _load_scalar_attributes raise exc.ObjectDeletedError("Instance '%s' has been deleted." % state_str(state)) sqlalchemy.orm.exc.ObjectDeletedError: Instance '<User at 0x2115410>' has been deleted. After perusing the sqlalchemy sources, I realized that when session.commit() is called, it is indeed inserting the data into the database, but it is not updating the _rowid primary key on the User object that was created. The user object looks in the database for something with an id of 'None', which doesn't exist, causing it to think its deleted. Can anyone tell me what I need to change in my dialect to make this work? I've been toying with a post_exec on the ExecutionContext that is similar to the one for SQLite and I've been trying to understand how the last_inserted_ids are generated in the sqlalchemy default.py, but I'm not sure if I'm on the right track. Also, does anyone know of a tutorial or guideline for writing Alchemy dialects? Trying to get it from the source code of the existing databases is, while enlightening, taking a lot of time to grok. Thanks, Dusty --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---