The actual fix for this is in r5052.  The ticket is not complete as  
tests have not yet been added but your test now passes.


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

> Further to below , if I do :
>
> >>> u.id = 9
> >>> session.commit()
> 2008-08-22 15:16:54,066 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 15:16:54,082 INFO sqlalchemy.engine.base.Engine.0x..70  
> [9, 8]
> 2008-08-22 15:16:54,082 INFO sqlalchemy.engine.base.Engine.0x..70  
> COMMIT
> >>> u
> 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70  
> BEGIN
> 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70  
> SELECT users.i
> d AS users_id, users.name AS users_name
> FROM users
> WHERE users.id = ?
> 2008-08-22 15:16:55,332 INFO sqlalchemy.engine.base.Engine.0x..70 [9]
> <User ID : 9, Name : One>
> >>> u.id = 11
> >>> session.commit()
> 2008-08-22 15:17:03,630 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 15:17:03,630 INFO sqlalchemy.engine.base.Engine.0x..70  
> [11, 9]
> 2008-08-22 15:17:03,630 INFO sqlalchemy.engine.base.Engine.0x..70  
> COMMIT
>
> That is, before setting the id to a new value, if I just let the  
> session do its query (since the object is expired after prev  
> commit), there seems to be no problem in further commits. But as I  
> mentioned in the below mail, using session.flush() without letting  
> the session do its query seems to work. Does flush internally query  
> and get the object before flushing it to DB which commit() doesn't  
> seem to do?
>
> ---------- Forwarded message ----------
> From: Harish K Vishwanath <[EMAIL PROTECTED]>
> Date: Fri, Aug 22, 2008 at 3:02 PM
> Subject: Autoexpire on commit is causing problems?
> To: sqlalchemy@googlegroups.com
>
>
> Hello, I am SQLA 0.5beta4r5051.  I am having issues with session  
> having expire_on_commit as True. Below is an example :
>
> File : sqla05betatest.py
> from 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()
> 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70  
> BEGIN
> 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70  
> [1, 1]
> 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70  
> ROLLBACK
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\session.py", line 663, in commit
>     self.transaction.commit()
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\session.py", line 375, in commit
>     self._prepare_impl()
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\session.py", line 359, in _prepare_impl
>     self.session.flush()
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\session.py", line 1351, in flush
>     self._flush(objects)
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\session.py", line 1419, in _flush
>     flush_context.execute()
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\unitofwork.py", line 265, in execute
>     UOWExecutor().execute(self, tasks)
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\unitofwork.py", line 757, in execute
>     self.execute_save_steps(trans, task)
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\unitofwork.py", line 772, in execute_save_steps
>     self.save_objects(trans, task)
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\unitofwork.py", line 763, in save_objects
>     task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
>   File "c:\python24\lib\site-packages\SQLAlchemy-0.5.0beta4dev_r5051- 
> py2.4.egg\s
> qlalchemy\orm\mapper.py", line 1206, in _save_obj
>     raise exc.ConcurrentModificationError("Updated rowcount %d does  
> not match nu
> mber of objects updated %d" % (rows, len(update)))
> sqlalchemy.orm.exc.ConcurrentModificationError: Updated rowcount 0  
> does not matc
> h number of objects updated 1
>
> When I set u.id = 1, session.add(u), session.commit() , It should've  
> issued an UPDATE sql updating id from '0' to '1'.  But instead :
>
> 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 14:50:51,477 INFO sqlalchemy.engine.base.Engine.0x..70  
> [1, 1]
>
> Why is this?
>
> Now, If I use Flush instead of commit (but the session is autoflush  
> = False, and autocommit=False)
>
> >>> u.id = 1
> >>> session.add(u)
> >>> session.flush()
> 2008-08-22 15:00:08,470 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 15:00:08,470 INFO sqlalchemy.engine.base.Engine.0x..70  
> [1, 0]
> >>> u.id = 2
> >>> session.add(u)
> >>> session.flush()
> 2008-08-22 15:00:30,375 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 15:00:30,375 INFO sqlalchemy.engine.base.Engine.0x..70  
> [2, 1]
> >>> u.id = 3
> >>> session.add(u)
> >>> session.flush()
> 2008-08-22 15:00:40,688 INFO sqlalchemy.engine.base.Engine.0x..70  
> UPDATE users S
> ET id=? WHERE users.id = ?
> 2008-08-22 15:00:40,688 INFO sqlalchemy.engine.base.Engine.0x..70  
> [3, 2]
>
>
> It issues the proper SQL and there are no exceptions.
>
> Why is this happening?
>
>
>
>
> -- 
> Regards,
> Harish
>
> >


--~--~---------~--~----~------------~-------~--~----~
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