Sqlachemy的警告SAWarning: The IN-predicate on "sns_object.BIZ_ID" was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.

我在使用db_session.query,查询的时候idlist是个空值时候,执行下面的语句就会出现警告。
其中后面delete(synchronize_session=False)是删除前面的一堆查询相当于查出符合条件的数据。
synchronize_session用于query在进行delete or update操作时,对session的同步策略。False - 不对session进行同步,直接进行delete or update操作。
        db_session.query(CommentInfo).filter(CommentInfo.BIZ_ID.in_(idlist)).filter(CommentInfo.MEDIA_TYPE=="INS").delete(synchronize_session=False)

  

def delete_exist_bizid(self,dics):
    idlist=dics.get("BIZ_ID")
    db_session.query(CommentInfo).filter(CommentInfo.BIZ_ID.in_(idlist)).filter(CommentInfo.MEDIA_TYPE=="INS").delete(synchronize_session=False)
    db_session.commit()
if __name__=="__main__": dics={"BIZ_ID":[]} SaveData().delete_exist_bizid(dics)

  

解决方案:加一个判断条件当BIZ_ID的值不为空的时候,才进行后面删除操作。 
原文地址:https://www.cnblogs.com/c-x-a/p/8863950.html