- changed status to invalid
Object is already attached error occuring intermittently
Apologies for a slightly sketchy bug report, if it is that. This issue occurs intermittently and I'm having trouble isolating a simple example which reproduces it.
The issue is that the Error thrown at orm/session.py line 1102, in _attach is occuring at times, and I can't explain why. If I simply modify the lines
if old_id is not None and old_id in _sessions and instance in _sessions[old_id](old_id):
raise exceptions.InvalidRequestError("Object '%s' is already attached "
"to session '%s' (this is '%s')" %
(mapperutil.instance_str(instance), old_id, id(self)))
to
if old_id is not None and old_id in _sessions and instance in _sessions[old_id](old_id):
return
Then everything works fine for me.
The error seems to be telling me that I've created two sessions and my instance is attached to the other session. I'm not aware of creating more than one session anywhere in the code - I'm working inside Turbogears. Perhaps if you could explain a little more what situation this is checking for then I can get to the bottom of it. Is it normal for there to be more than one session going on unless you explicitly create it?
Comments (1)
-
repo owner - Log in to comment
turbogears uses an extension to Mapper which causes newly created objects to be automatically saved to the current contextual session. Therefore you need to either find a way to turn this nasty option off (its the save_on_init=False argument to mapper()), or explicitly expunge() the object from the contextual session first.
this is more of a mailing list issue so closing this ticket.