I am trying to return the value of my SELECT query from my context manager. However, nothing is returned as a response. How can I return the results of my select query from my context manager/session?
@contextmanager
def aperio_session_scope():
"""Provide a transactional scope around a series of operations."""
session = AperioSession()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()
In addition, the query class looks like this:
class AperioSlidesAfterDate(object):
def go(self, session):
session.query(Slide).join(Image).filter(Image.scandate > '2018-08-01 00:00:00', Slide.barcodeid.isnot(None))
I run the query as follows:
with aperio_session_scope() as session:
slides = AperioSlidesAfterDate().go(session)
All 3 of these snippets are from different files and my imports are set up properly. No compile time or runtime exceptions. It seems that the value of slides
is always None
. Am I missing something? I followed the examples from SQLAlchemy docs.
If I do something like:
with aperio_session_scope() as session:
slides = session.query(Slide).join(Image).filter(
Image.scandate > '2018-08-01 00:00:00', Slide.barcodeid.isnot(None))
I get results, but I want to try an and use the session object with go as intended in the documentation. Is this a scoping issue? Or do I just need to somehow access the return value if at all possible?
Thanks.