Without seeing more detail, my first impression looks like this:
class SomeXMLObject(object):
def modified(self):
return self._modified
def set_modified(self, x):
self._modified = x
self.parent.modified = x
modified = property(modified, set_modified)
The related object would need to explicitly propagate to its parent
object.
>
> On 27 Lip, 22:43, Michael Bayer <mike...@zzzcomputing.com> wrote:
>>
>> The related object would need to explicitly propagate to its parent
>> object.
>
> My 'modified' is a column which stores time. It should get updated
> when an instance is modified (dirty). I am populating this column in a
> session extension. However, changes made to a contained XML document
> doesn't make container object dirty and the session extension
> before_insert/update is not called.
SessionExtension doesn't have a before_insert/update method, do you
mean MapperExtension ?
> Anyway, in my application many different classes contains XML data.
> Simple 'parent' backref won't work, because it would be ambiguous to
> which class it refers (unless I use a common base class for all
> entities which contains XML).
as long as the parent is using relation() to the child, the child is
capable of having a backref. If the child is capable of being
attached to many kinds of parent, then it would have many kinds of
backref - pick the non-None one to find the path to the parent.
Since you need to change the flush plan before it happens, the
SessionExtension before_flush() is the only place you can hook this
operation in implicitly. Scan for dirty objects of the appropriate
type and then mark their parent object dirty. The work you do within
before_flush() can replace the before_insert()/before_update() hook
you're using.