sqlalchemy.exc.InvalidRequestError

时间:2018-12-21 23:02:11

标签: python sqlalchemy

我正在尝试建立数据库并保存用户afk状态及其原因,但是我总是会遇到以下错误:sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped entity expected - got '{}'

from sqlalchemy import Boolean, Column, UnicodeText

from tg_userbot.modules.sql import BASE, SESSION

class AFK(BASE):
    __tablename__ = "afk"
    is_afk = Column(Boolean, primary_key=True)
    reason = Column(UnicodeText)

    def __init__(self, reason="", is_afk=True):
        self.reason = reason
        self.is_afk = is_afk


def set_afk(reason=""):
    cursor = SESSION.query(AFK).get(is_afk)
    if not cursor:
        cursor = AFK(reason, True)
    else:
        cursor.is_afk = True
        cursor.reason = reason
        AFK["is_afk"] = reason

    SESSION.add(cursor)
    SESSION.commit()

def __load_afk_state():
    global AFK
    try:
        cursor = SESSION.query(AFK).get(is_afk)
        if cursor:
            AFK["is_afk"] = cursor.reason
    finally:
        SESSION.close()


__load_afk_state()

该脚本应将is_afk列设置为True,如果他说出保存它的理由,则应改为上面的错误。有解决方案吗?

0 个答案:

没有答案