Logging SA objects *after* the session is gone will always be a
problem, unless you make sure to detach all of them from the session.
I'd just log the original request, instead. In my case, I have to
convert all of my SA objects to something Perspective Broker
understands, so I actually log those *after* that, as they're no
longer part of the session--but I'm not sure if you can do that in
your case.
As for the decorator--I got a little confused with your names--you
call it "model" in your decorator, but it's really an instance of
Database when it gets passed in as "self". One way to get rid of that
parameter would be to make sess a keyword argument, like so:
def wrapper(*args, **kw):
sess = model.Session()
try:
return f(sess=sess, *args, **kw)
and then change your method:
def _getObjectById(self, klass, id, sess=None):
return sess.query(klass).get(id)
That way, "self" will get passed in *args with no problem.
Are you planning to have multiple instances of your Database class?
If not, I'd suggest changing everything in it into class methods, so
that way you can call it *without* an instance at all, and don't have
to worry about connecting to the database multiple times by accident.
Just a thought.
-Jeff