Flask 独特炼金术+;其中返回空集

Flask 独特炼金术+;其中返回空集,flask,sqlalchemy,flask-sqlalchemy,Flask,Sqlalchemy,Flask Sqlalchemy,我有一个数据库,其中包含列commune和liste。这些字段不为null,因此任何选择其中一个字段并在另一个字段上设置WHERE约束的查询都应该成功。(在下面的示例中,我已经确认它作为原始SQL确实成功。) 如果我这样写: communes = db.session.query(SurveyResponder.commune.distinct()).all() 我得到了一个不同的公社价值观列表。如果我取其中一个值并写下 commune = communes[0][0] # The ex

我有一个数据库,其中包含列
commune
liste
。这些字段不为null,因此任何选择其中一个字段并在另一个字段上设置WHERE约束的查询都应该成功。(在下面的示例中,我已经确认它作为原始SQL确实成功。)

如果我这样写:

communes = db.session.query(SurveyResponder.commune.distinct()).all()
我得到了一个不同的公社价值观列表。如果我取其中一个值并写下

commune = communes[0][0]    # The extra dereference just copes with all() returning tuples.
lists = db.session.query(SurveyResponder.liste.distinct()).filter_by(commune=commune).all()
我得到一个空的结果集:

[('',)]
如果我看一下生成的SQL

db.session.query(SurveyResponder.liste.distinct()).filter_by(commune=commune)
我看到这样的SQL:

SELECT DISTINCT survey_responder.liste AS anon_1 
FROM survey_responder 
WHERE survey_responder.commune = ?
如果我换新的?通过公社结果的真实论证,我看到了结果:

$ sqlite3 dev.db 
SQLite version 3.27.2 2019-02-25 16:06:06
Enter ".help" for usage hints.
sqlite> SELECT DISTINCT survey_responder.liste AS anon_1 
   ...> FROM survey_responder 
   ...> WHERE survey_responder.commune = 'Vertou';
Vertou naturellement
Vertou’S
Soyons Vertou

sqlite> 

我怀疑我犯了一些愚蠢的语法错误,但我没有找到它。有指针吗?

[('',)]
不是空的。它是一行一列字符串的结果,然后恰好是一个长度为0的字符串。啊哈,你说得很对。虽然该列不能为null,但显然可以为空。它几乎从来都不是(也不应该是,但数据来自人类),除了我玩的两个例子。谢谢