On Mar 29, 2012, at 6:48 AM, lars van gemerden wrote:

> I think I have an odd case of the first possibility you mentioned:
> 
> I am generating XML from SAclass objects opdating these objects from
> XML. To detect cyclic references and double objects, I maintain a
> registry of objects based on id() (reg[str(id(obj))] = obj). The id is
> stored as the attribute "ID" in the XML tag. When updating the objects
> I first look them up in the registry obj = reg[etree.get("ID")] and
> update them afterwards. I do this as well with relationships/
> InstrumentedLists (but not with database fields like Integer).
> 
> What I noticed was that InstrumentedList changes id() after a commit
> (with a = Address(), Address.persons = relationship(...) ):
> 
>    print id(a), id(a.persons), id(a.persons[0])
>    session.commit()
>    print id(a), id(a.persons), id(a.persons[0])
> 
> gives:
> 
> 47148168 47174264 47114112
> 47148168 47175784 47114112 (the middle id has changed)
> 
> So I assume that after a commit a new InstrumentedList is created.

that's only because commit() expires all attributes and collections, so you get 
a new one on next access.


> 
> - Could it be conceivable that is causes the warning mentioned
> above(an old version of the InstrumentedList being updated with an
> valid SAclass object)?

the InstrumentedList itself is not something that's tracked by the session, 
it's only a container stuck on the parent object.    Somehow a.persons[0] or 
some other element is being expunged from the session, or is not being placed 
inside to start with.

As always, if you could demonstrate the warning with a small test case I can 
quickly determine what the exact cause is.

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