On Aug 22, 2013, at 5:58 PM, Hans-Peter Jansen <h...@urpla.net> wrote:

> Dear Michael,
> 
> 
> Hmm, it looks like that needs to be applied on every column attribute..

> 
>> you can get a list of all attributes mapped using mapper.attrs:
>> http://docs.sqlalchemy.org/en/rel_0_8/orm/mapper_config.html?highlight=mapp
>> er.attrs#sqlalchemy.orm.mapper.Mapper.attrs
> 
> from here. Since I need to track all 'net' changes, that's rather unpractical.

if you're just looking for "dirty" you can look at session.dirty itself, such 
as in a before_flush() handler....not sure what the specific scenario is.


> That is: just change instance attributes in place, and check for dirtiness 
> later on, with session.is_modified(obj, passive = True). I've chosen this 
> interface, because the fact of *really* being modified is essential here.
> 
> This scheme would do just fine, but doesn't work as expected.
> 
> See attached code. Depending on modification state of parent (line 51), the 
> modification state of the child is detected (parent changed) or not (parent 
> unchanged).

it looks like this code makes a change to p.children[0].name, and then expects 
that session.is_modified(p) would be True.    is_modified() is per-object, so 
modifying Child means that just Child is modified, Parent hasn't changed at 
all.   If you want to make an "is_modified()" that recurses through object 
graphs, you'd need to traverse down yourself through related attributes.   I 
can show you what that looks like if this is what you want.

> In my real code, it's the other way around, modifications to relations are 
> detected (as I iterate through all of them), but changes to the "parent" 
> aren't, although the correct SQL UPDATE code is executed after commit(). 
> Since 
> it isn't detected correctly, my app falls flat on its nose..

well if you change Child.name, the only UPDATE needed is on the "child" table.  
the "parent" table doesn't require an UPDATE in this case which is why 
session.is_modified() returns False.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to