Use SQLAlchemy events instead of deprecated SessionModificationExtension

This shouldn't affect the behavior in any way.

This is done
* because it has to be done at some point anyway
* and in order to track #317 down.