Returning a value from a SQLAlchemy context manager : <p>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?</p>

<pre><code>@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()
</code></pre>

<p>In addition, the query class looks like this:</p>

<pre><code>class AperioSlidesAfterDate(object):
  def go(self, session):
    session.query(Slide).join(Image).filter(Image.scandate &gt; '2018-08-01 00:00:00', Slide.barcodeid.isnot(None))
</code></pre>

<p>I run the query as follows:</p>

<pre><code>  with aperio_session_scope() as session:
    slides = AperioSlidesAfterDate().go(session)
</code></pre>

<p>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 <code>slides</code> is always <code>None</code>. Am I missing something? I followed the examples from SQLAlchemy docs.</p>

<p>If I do something like:</p>

<pre><code>with aperio_session_scope() as session:
    slides = session.query(Slide).join(Image).filter(
        Image.scandate &gt; '2018-08-01 00:00:00', Slide.barcodeid.isnot(None))
</code></pre>

<p>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?</p>

<p>Thanks.</p>
