Hi Connor,

On 13 oct, 18:23, Conor <conor.edward.da...@gmail.com> wrote:
>   On 10/13/2010 10:55 AM, Christophe de Vienne wrote:
>
>
>
> > Hi all,
>
> > I am running into an issue with MapperExtension.[before|after]_update.
>
> > [...]
>
> AFAIK SQLAlchemy does not support the following in MapperExtensions:
>
>     * lazy-loading related objects (maybe?)

It looks like this. Because if I make sure the related objects are
loaded before flushing the problem.

>     * changing the "flush plan", which I believe means changing which
>       objects are considered new, dirty, or deleted

Which is why I do a double flush.

> Your code is possibly trying to do both.

Yep, but the disturbing thing is that I could not reproduce the issue
in a small example, hence my question.

> You need to instead create a
> SessionExtension and override before_flush, which allows you to modify
> the session however you want, e.g. (untested):
>
> class MySessionExtension(object):
>      def before_flush(self, session, flush_context, instances):
>          for obj in session.dirty:
>              if isinstance(obj, Parent):
>                  for child in obj.children:
>                      child.name = 'another name'

This is a very interesting idea, which beside solving my issue
(hopefully) would also avoid a double-flush.

I guess I should also have a look to AttributeExtension which could be
a solution in my case.


Thanks,

Christophe

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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