code: def magic_session(db_session=None, url=None):
      
  
      if db_session is not None:
          yield db_session
      else:
          session = get_session(url, expire_on_commit=False)
          try:
              try:
                  yield session
              finally:
                  session.commit()
          finally:
              session.close()
docs: Either does nothing with the session you already have or
      makes one that commits and closes no matter what happens