this is a bug and has been filed as ticket 1151.    Changing the  
primary key value on a mapped instance incurs special logic so this  
error is limited to that case, as a workaround ensure that the object  
is refreshed before modifying a primary key column.


On Aug 22, 2008, at 5:32 AM, Harish K Vishwanath wrote:

> rom sqlalchemy import create_engine, Table, Column, Integer, String,  
> MetaData
> from sqlalchemy.orm import mapper, sessionmaker
> engine = create_engine("sqlite:///:memory:",echo=True)
>
> class User(object):
>     def __init__(self,name="anonymous"):
>         self.id = 0
>         self.name = name
>
>     def __repr__(self):
>         return "<User ID : %s, Name : %s>" % (repr(self.id),self.name)
>
> metadata = MetaData()
> usertable = Table('users',metadata,
>                   Column('id',Integer,primary_key=True),
>                   Column('name',String(50))
>                   )
>
> metadata.create_all(engine)
>
> mapper(User,usertable)
> Session = sessionmaker(bind=engine,autocommit=False,autoflush=False)  
> #expireoncommit is True
> session = Session()
>
> Now using Python 2.4 interpreter :
>
> >>> from sqla05betatest import *
> 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70  
> PRAGMA table_i
> nfo("users")
> 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 {}
> 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70
> CREATE TABLE users (
>         id INTEGER NOT NULL,
>         name VARCHAR(50),
>         PRIMARY KEY (id)
> )
>
>
> 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70 {}
> 2008-08-22 14:50:17,852 INFO sqlalchemy.engine.base.Engine.0x..70  
> COMMIT
> >>> u = User("One")
> >>> session.add(u)
> >>> session.commit()
> 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70  
> BEGIN
> 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70  
> INSERT INTO us
> ers (id, name) VALUES (?, ?)
> 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70  
> [0, 'One']
> 2008-08-22 14:50:32,150 INFO sqlalchemy.engine.base.Engine.0x..70  
> COMMIT
> >>> u.id = 1
> >>> session.add(u)
> >>> session.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to