[storm] Audit trail / Change log

James Henstridge james at jamesh.id.au
Fri Aug 29 17:22:06 BST 2008


On Fri, Aug 29, 2008 at 9:05 PM, Gerdus van Zyl <gerdusvanzyl at gmail.com> wrote:
> By reading the source I came up with the following code. It seems to
> work. I am always pleasantly surprised at storm's flexibility.
>
> (warning non-relevant code omitted,won't run as is)
> from storm.info import get_obj_info
> from storm import Undef
> # in eg. constructor
> store = getStore()
> obj_info = get_obj_info(self)
> self._enable_change_notification(obj_info)
>
> def _enable_change_notification(self, obj_info):
>      obj_info.event.hook("changed", self._variable_changed)
>
> def _variable_changed(self, obj_info, variable,
>                          old_value, new_value, fromdb):
>    if not fromdb:
>           if new_value is not Undef and new_value is not AutoReload:
>                print 'Change:',variable.column.name,old_value,new_value

Note that this is not guaranteed to track all changes -- just the ones
done on individual objects.  The following code would probably bypass
your callbacks:

    store.find(SomeTable).set(column=42)

This will update every row of the table, irrespective of whether there
is a Python object loaded to represent the row.  If you want something
that will catch all changes, you might be better off going lower level
with a database trigger or higher level above where you use the Storm
API.

James.



More information about the storm mailing list