sqlalchemy查询有时会失败

时间:2017-10-11 06:53:16

标签: python sqlalchemy

我的数据库有一个表player,我使用sqlalchemy来获取数据:

    def get_player(self, _openid):
      session = Session()
      try:
        result = session.query(PlayerDB).filter(PlayerDB.openid==_openid).one()
        player = PlayerDB.convert_to_player(result)
        session.close()
        return player
      except exc.SQLAlchemyError:
        logger.error('failed to get player from db, openid: %s' % _openid)
        session.close()
        return None


    def convert_to_player(self, result):
        player = Player()
        player._id = result._id
        player.openid = result.openid
        return player

使用相同的openid,有时get_player返回None,有时则没有。为什么会这样?

0 个答案:

没有答案