Give our sqlalchemy objects access to their own session
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 30 Nov 2014 16:58:11 +0000 (10:58 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 3 Dec 2014 21:40:56 +0000 (15:40 -0600)
mediagoblin/db/base.py

index 38375a6927b7bdb4432de3060cdadb870e882bb2..e254e810f7d4666253cf69d457d4c614f17122f4 100644 (file)
 
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import scoped_session, sessionmaker, object_session
+from sqlalchemy import inspect
 
 Session = scoped_session(sessionmaker())
 
 
+
 class GMGTableBase(object):
+    @property
+    def _session(self):
+        return inspect(self).session
+
     query = Session.query_property()
 
     def get(self, key):