the first set of operations on the Session place every new object,  
including two Address objects and two GenericAssoc objects, in the  
session.  Then the session is cleared.  Then, a series of loads load  
in all those same objects, including the same Address objects and  
GenericAssoc objects, except different instances of them local to that  
session (since the previous were cleared).  Then, when u2 = User() is  
created and is associated with "a2" from the *first* session, the two  
original GenericAssoc objects (which were cleared) now become  
associated with that User object via the connection to Address, which  
fail to be added since there are already two GenericAssoc's from the  
second Session usage present.

On Jul 3, 2008, at 9:31 AM, Gaetan de Menten wrote:

> Hi list,
>
> Could anybody tell me what's wrong with the following code? It's only
> the code in the poly_assoc example directory (the generic version)
> where I'm trying to set the polymorphic part of the relationship. It
> gets me the traceback below and I don't really understand why:
>
> Traceback (most recent call last):
>  File "poly_assoc_3.py", line 155, in <module>
>    sess.save(u2)
>  File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/util.py", line
> 1550, in func_with_warning
>    return func(*args, **kwargs)
>  File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/ 
> session.py",
> line 1055, in save
>    self._cascade_save_or_update(state, entity_name)
>  File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/ 
> session.py",
> line 1111, in _cascade_save_or_update
>    self._save_or_update_impl(state)
>  File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/ 
> session.py",
> line 1251, in _save_or_update_impl
>    self._update_impl(state)
>  File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/ 
> session.py",
> line 1241, in _update_impl
>    "session." % (mapperutil.state_str(state), state.key))
> sqlalchemy.exc.InvalidRequestError: Could not update instance
> '[EMAIL PROTECTED]', identity key (<class
> '__main__.GenericAssoc'>, (1,), None); a different instance with the
> same identity key already exists in this session.
>
> -- 
> Gaƫtan de Menten
> http://openhex.org
>
> >
> <poly_assoc_3.py>


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