我的数据库有一个表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,有时则没有。为什么会这样?