the error means the object was loaded from the database in some session.  
it can't be sent to save().   if you send it to save_or_update() or add(),
it's already INSERTed as far as SQLA is concerned.

each test you create should not use any instances of your mapped entities
from the previous test.  when you remove the session, all state which was
associated with that session should be discarded.  you could alternatively
try to re-add those objects back in but that's cumbersome.  you should
also get onto 0.4.8 and use session.add() to keep things simple.



iain duncan wrote:
>
> Thanks Mike. I made some progress ( I think! ). I now have the test
> class setup method successfully creating a new scoped session on each
> pass, and the objects that were created originally in a turbogears
> session context are being saved into that session and flushed to the
> db. I think this is the right approach, fresh session for each fresh
> fixture.
>
> Now however, I'm getting the following on the second test:
> InvalidRequestError: Instance 'reg...@0x2db6950' is already persistent
> and looking at the session.identity_map, it's empty.
>
> If I replace session.save(obj) with session.save_or_update(obj) the
> exception does not get thrown. The new object *is* in the identity map
> of the new session at the end of the test, but no SQL to insert the
> object into the actual DB gets generated. ( I'm on sa 0.4.2, yes it's
> a bit of a legacy case... )
>
> I have the fixture drop and recreate the tables, so I'm hoping there
> is some way of copying these objects form their prototype declaration
> class into a new session and flush to the newly created tables on each
> pass.
>
> Any tips much appreciated again,
> Iain
> >
>


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

Reply via email to